C # Implementation Read Barcode

Source: Internet
Author: User

Barcode Scanner Selling GoodsExample DescriptionNowadays, many supermarkets use bar codes to sell goods. The computer operator uses the scanner to scan the barcode of the product, and the details of the product are displayed on the screen. This example realizes the use of bar code to sell goods function. The effect is shown in Figure 13.19.Technical PointsWhen you scan a barcode with a scanner, the barcode data is displayed in the window control that currently has the focus. For example, if the current edit box has the focus, the barcode data is displayed in the TextBox text box. It then sends a message to the TextBox text box when the ENTER key is pressed. In the program, just trigger the KeyDown event of the TextBox text box to determine if the current key is the enter, and if so, read the barcode data in the TextBox text box, and query the product information from the datasheet according to the barcode to display it in the DataGridView list.implementation Process (1) Create a new item, named Ex13_18, and the default form is Form1. (2) in the Form1 form, a TextBox control is mainly added to receive barcodes, and a DataGridView control is added to display the product sales information that the scanner scans for barcodes. (3) Main program code.         private void Textbox1_keydown (object sender, KeyEventArgs e)   & nbsp;     {            if (E.keyvalue = =             {                 OleDbConnection con = new OleDbConnection ("provider= Microsoft.jet.oledb.4.0;data source= "+" Price.mdb "+"; Persist security Info=false ");                 OleDbDataAdapter dap = New OleDbDataAdapter ("SELECT * from Merchandiseinfo where barcode= '" + TextBox1.Text + "", con);                  DataSet ds = new DataSet ();                 DAP. Fill (DS);                 if (ds. Tables[0]. Rows.Count = 0)                 {                      MessageBox.Show ("This product does not exist.") "," System hint ", MessageBoxButtons.OK, MessageBoxIcon.Information);                      return;                }                  for (int i = 0; i < Datagridview1.rowcount ; i++)                 {                     if (Convert.ToString ( Datagridview1[0, I]. Value) = = "")                      {                         datagridview1[0, I]. Value = ds. Tables[0]. Rows[0][0]. ToString ();                          datagridview1[1, I]. Value = ds. Tables[0]. ROWS[0][1]. ToString ();                          datagridview1[2, I]. Value = ds. Tables[0]. ROWS[0][2]. ToString ();                         Datagridview1[3, I]. Value = ds. Tables[0]. ROWS[0][3]. ToString ();                          return;                     }                }             }        }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.