简体   繁体   English

vb.net文本框验证针对数据库?

[英]vb.net textbox validation against a database?

one of the fields on my form is a textbox that the user types an id. 表单上的字段之一是用户输入ID的文本框。 this is the foreign key to another table so I need to bounce the data against that table before letting them submit. 这是另一个表的外键,因此我需要针对该表对数据进行反弹,然后再让它们提交。 I'd rather not use textchanged as every letter they type may incur another query, focus lost would only show an error or validate when they are already in another field (not sure if it would fire if they just clicked submit). 我宁愿不使用textchanged,因为他们键入的每个字母都可能会引起另一个查询,失去焦点只会在他们已经在另一个字段中时显示错误或验证(不确定是否只要单击提交即可触发)。

I would prefer not to force someone's focus to stay in that field, but perhaps that's the best way? 我不想强迫某人专注于该领域,但这也许是最好的方法?

Is there a method to sleep and wait to see if there is another incoming key event within X seconds? 是否有一种方法可以休眠,然后等待X秒钟内是否还有另一个传入的按键事件? if so can I peek to see if it's a letter or number vs a tab or return? 如果可以,我可以偷看一下是字母还是数字,而不是制表符还是返回?

Is there another event I should be hooking that's user friendly? 我应该钩住另一个用户友好的事件吗?

Should I pull down a copy of that column of the table and real time compare there? 我是否应该下拉该表的副本并在那里进行实时比较? (I could handle adding a refresh button to pull a new cache) (我可以添加一个刷新按钮来拉取新的缓存)

You may want to consider using a timer control for this. 您可能需要考虑使用计时器控件。

Disable and Enable the control every time the key is pressed, to reset the timeout. 每次按键时禁用和启用控件,以重置超时。

Then when the timer event fires, Disable the control and query the database. 然后,当计时器事件触发时,禁用控件并查询数据库。

EDIT: I still think your best bet is probably on the Lost Focus event. 编辑:我仍然认为您最好的选择可能是在失去焦点事件上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM