改进文本框 C# 中的条码搜索 [英] Improve Barcode search in a Textbox C#

查看:28
本文介绍了改进文本框 C# 中的条码搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WinForm C# 应用程序中,我有一个 Barcode_textbox.在 TextChanged 事件中,我有一个 SQL 查询来检查作为条形码的数据库中的 TextBox.Text 值.问题是对于每个输入的数字都会触发 SQL 查询,因此如果长度为 13 的条形码将在数据库中进行 13 检查,并且速度非常慢.

In a WinForm C# application I have a Barcode_textbox. In TextChanged event I have an SQL query to check for the TextBox.Text value in the database which is the barcode. The problem is that for each entered digit the SQL Query will be fired, so if a barcode of length 13 it will make 13 check in the database and it is being extremely SLOW.

那么,只有当用户停止在 TextBox 中写入(或条码阅读器 stpos 读取)时才会触发的 TextBox 事件是什么,或者检查数据库中条码的最佳解决方案是什么.注意bacode长度不同

So, what is the TextBox event that is fired only when the user stops writing in the TextBox (or the barcode reader stpos reading), or what is the optimal solution for checking for a barcode in the database. Note that bacode is of different length

推荐答案

我记得我是如何成功地做到这一点的.

I recall how I did this with success.

我以一秒(1000 毫秒)的间隔将 Timer 控件放入我的应用程序中.然后我将 Form.KeyPreview 属性设置为 True.

I put Timer control in my application with a Interval of a second (1000 milli's). Then I set the Form.KeyPreview property to True.

在 Form Key Press 事件中,我存储击键.在 Timer.Tick 事件中检查记录的击键长度是否超过 12 个字符左右.

In the Form Key Press event I store the key strokes. In the Timer.Tick event check if the length of the recorded key strokes exceeds 12 or so characters.

然后触发对 SQL 的调用,一次.当您成功返回记录时(或者如果文本框包含超过 20 个字符)清除存储的键击.

Then fire off the call to SQL, once. When you return a record successfully (or if the textbox contains greater than say 20 chars) clear the stored key strokes.

查看更新,截至 2019 年 3 月:https://stackoverflow.com/a/55411255/495455

这篇关于改进文本框 C# 中的条码搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆