Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
how can i read from barcode scanner in text box and add it in data base then when i read next time the previous reading is deleted and the new one appears in text box
Posted
Comments
Michel [mjbohn] 15-Apr-11 3:01am    
Could you please consider accepting one of the solutions if it was helpful for you?

Check if if there is a barcode onRead or something similar.
If you have something like this, as soon as it fires, you can clear the textbox.

It could also be done in another way. Clear your textbox just before you place your barcode text into the box - but for that your code needs to be seen.
 
Share this answer
 
Comments
Mohammed Ahmed Gouda 11-Apr-11 7:53am    
sorry but can u help me with the code coz i am an amatuer with programming ?
you could try this

C#
private void textBox1_TextChanged(object sender, EventArgs e)
{
// your DB stuff here...
MessageBox.Show(string.Format("{0} entered in database", textBox1.Text));
this.ActiveControl = textBox1;
textBox1.SelectAll();
}
 
Share this answer
 
v2
Comments
Mohammed Ahmed Gouda 11-Apr-11 8:19am    
it work but it just take the first number from the barcode and add it to DB
Michel [mjbohn] 11-Apr-11 8:30am    
oh yes that's right. I forgott that these scanners work like if you type on keyboard. So textBox1_TextChanged is trigered for every single char that comes in. Let me think about it again
Kim Togo 11-Apr-11 8:32am    
But the complete barcode appearers in the TextBox ?
Try post how you insert the barcode in the database.
Michel [mjbohn] 11-Apr-11 8:45am    
not the barcode itself will be in the textbox. Just the string (digits and chars) can be displayed in the textbox. That's all the scanner will send
Kim Togo 11-Apr-11 8:47am    
Okay :-) - But the problem is that, OnReadBarcode event is called for every single digits and chars of the barcode ? - Is there a end marker (end of barcode) ?
I had a look at the user manual. The scanner is sending keystrokes. The keystroke it sends is the 'enter' key.
What I didn't find out is, whether this is default configuration or not. But it is quite easy to configure by scanning some barcodes from the manual.
Assumig that 'enter' key is configured as last sign, this might be your solution with using the KeyDown event of the textBox.

C#
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        // Your DB stuff
        // MessageBox.Show(textBox1.Text);
        this.ActiveControl = textBox1;
        textBox1.SelectAll();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900