【发布时间】:2019-01-29 13:00:47
【问题描述】:
当我扫描条形码时,它只显示数据库中的一个数字条形码。我的其他长号条码没有显示出来
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if ((e.KeyCode != Keys.Enter) || (textBox4.Text.Length == 0))
{
return;
}
conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Database\book1.mdf;Integrated Security=True;Connect Timeout=30");
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter("SELECT productid,ProductName,Description,Stock,UOM,Price from ProductTable where productId='" + textBox4.Text + "'", conn);
DataTable dt = new DataTable();
adp.Fill(dt);
foreach (DataRow item in dt.Rows)
{
int i = dataGridView1.Rows.Add();
DataGridViewRow row = dataGridView1.Rows[i];
row.Cells[0].Value = item[0].ToString();
row.Cells[1].Value = item[1].ToString();
row.Cells[2].Value = item[2].ToString();
row.Cells[3].Value = item[3].ToString();
row.Cells[4].Value = item[4].ToString();
row.Cells[5].Value = item[5].ToString();
}
conn.Close();
}
textBox4.Text=" ";
}
页面截图:
【问题讨论】:
-
你想完成什么?
-
我只想扫描多位数字条码
-
如果您使用 KeyDown 事件 - 您可能会在条形码中的每个字符中获得一个事件。您可以等到从条形码阅读器收到终止字符(如果有)。或者等到按钮被点击。
标签: c# barcode barcode-scanner keydown