I wrote these to try to read the data that appear on the textbox when the barcode reader is pointed on a barcode book for example. But its doesnt. Anyone can explain please.
private void codigoBarraConsStocks_KeyPress(object sender, KeyPressEventArgs e)
{
string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=master;Integrated Security=True";
string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=master;Integrated Security=True";
SqlConnection sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
string commandString = "select * from consultoria where codigobarra ='" + codigoBarraConsStocks.Text + "'";
SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
SqlDataReader read = sqlCmd.ExecuteReader();
if (read.HasRows)
{
while (read.Read())
{
codigoBarraStocks.Text = read["codigobarra"].ToString(); // it will show the code
produtoStocks.Text = read["produto"].ToString(); // it will show the code
precoStocks.Text = read["preco"].ToString(); // it will show the code
nStocksStocks.Text = read["n_stocks"].ToString(); // it will show the code
}
}
else
{
MessageBox.Show("A record with a code of " + codigoBarraConsStocks.Text + " was not found");
}
read.Close();
sqlCon.Close();
}
IsraelPosted Sep 18, 2014, 7:59 PM
I do try it. But its read just the first number of the barcode (9789804714405)
Wim SturkenboomPosted Sep 18, 2014, 2:46 AM
put a breakpoint on the first line of your method
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\office.mdb;Persist Security Info=False";
To do so, place the text cursor in the line and press
Alternatively, you can add the following lines just before the the above line; they will show the values that the program sees.
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
string txt1 = tb.Text;
string txt2 = textBox1.Text;
MessageBox.Show(String.Format("txt1: {0}\r\ntxt2: {1}", txt1, txt2), "TextBox1 content");
// rest of your code
Does this new messagebox show? If not, the TextChanged event is not triggered. If it shows,
what are the values that it displays for txt1 and txt2?
I unfortunately don't have a barcode reader so can only simulate using copy and paste.
IsraelPosted Sep 17, 2014, 4:30 PM
When I focus on a barcode that's on the product. Its not happear in the textbox1. After focusing on the barcode its show ONLY zero (0) in the textbox1 without filtering the product to show on the textbox2.
In final, its doesnt show any error. That why I didnt talk about the error.
My code:
Wim SturkenboomPosted Sep 17, 2014, 11:23 AM
Secondly inside of textbox on textchanged event. Its doesnt.
[/quote]
Please be more specific; it doesn't work means nothing. Do you get errors when running the code? Is the textchanged event triggered (put a breakpoint in it) when you scan? If so, what is the value of the textBox.text (not the visual one in the UI, but in code behind); does it reflect whatever you scanned or is it corrupted?
IsraelPosted Sep 17, 2014, 8:44 AM
Firstly when I try inside of button. Its works!:
Secondly inside of textbox on textchanged event. Its doesnt. Why? See my code please:
What happen. Need your support please. Thanx!
Anupam SinghPosted Sep 6, 2014, 12:08 AM
Nitesh KejriwalPosted Sep 6, 2014, 12:07 AM