Israel

Israel

  • 705
  • 1.3k
  • 216.4k

SOLUTION: Great codes to read data with barcode scanner

Oct 18 2014 9:03 AM
For those are looking for long time to read data with the barcode scanner. These codes will help a lot and works no problem. Thanx


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string lastScannedCode = "";
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
lastScannedCode = textBox1.Text;
label1.Text = lastScannedCode;
textBox1.Clear();
}
}
void ShowTheLastScannedCode()
{
MessageBox.Show(lastScannedCode);
}
private void label1_TextChanged(object sender, EventArgs e)
{
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TestBarcodeReader\WindowsFormsApplication1\WindowsFormsApplication1\App_Data\office.mdb;Persist Security Info=False";
OleDbConnection sqlCon = new OleDbConnection(connectionString);
sqlCon.Open();
string commandString = "select * from barcode where code ='" + label1.Text + "'";
OleDbCommand sqlCmd = new OleDbCommand(commandString, sqlCon);
OleDbDataReader read = sqlCmd.ExecuteReader();
if (read.HasRows)
{
while (read.Read())
{
label2.Text = read["products"].ToString(); // it will show the code
}
}
else
{
MessageBox.Show("A record with a code of " + label1.Text + " was not found");
}
read.Close();
sqlCon.Close();
}
}
}


Answers (1)