需要VB.NET代码来验证输入的数据并保存在Access 2003数据库中. [英] Need VB.NET code to validate data entered and saved in Access 2003 Database.

查看:73
本文介绍了需要VB.NET代码来验证输入的数据并保存在Access 2003数据库中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助.

我在VB.NET中创建了一个Windows应用程序,该应用程序收集用户输入并将其存储在MS Access 2003数据库中.

但是,我一直在寻找可用于验证通过VB.NET界面输入的信息的VB.NET代码,最重要的是,我想要用于验证输入数据的代码是否在数据库中重复进行复制的代码.

具体来说,我想要代码来验证输入的主键,从而产生重复的记录.

谢谢.

Need Help.

I have created a Windows application in VB.NET which collects user inputs and stores them in MS Access 2003 database.

However I have been searching for VB.NET code that I can use to validate information entered through the VB.NET interface, most importantly I want code that would validate data entered from being duplicated in the database.

Specifically, I want code that would validate the primary key from being entered which would produce a duplicated record.

Thanks.

推荐答案

在MS Access中,如果您将密钥设置为主"并且它是唯一的,那么您将不可能输入重复的值.数据库不允许您对已存在的键执行重复的操作.

如果通过代码执行此操作,则需要对数据库执行SQL语句以查找键值.如果未返回任何记录,则说明您的键值是唯一的.

请注意,如果您要处理数据库中的大表,并且由于它是Access,则很可能会出现性能问题.

我建议您使用SQL Server Express 2005/2008,它轻巧,功能强大,并且性能优于MS Access.它还将允许您使用存储过程和触发器以及其他功能.祝你好运!

HTH
In MS Access if you set your key to be Primary and it is unique then it would be impossible for you to enter a duplicate value. The database won''t let you perform a duplicate action on a key that already exists.

If you are doing this through code then you would want to perform a SQL statement against the database looking up the key value. If no records are returned then you know that your key value is unique.

Please note, that if you are going up against a large table in your database, and since it is Access, you are going to most likely have problems with performance.

I would recommend that you use SQL Server Express 2005/2008, it is lightweight and powerful and is better in performance than MS Access. It will also allow you to use Stored Procedures and Triggers among other things as well. Good luck!

HTH


进一步了解Slacker007的答案

如果您在主键"列中输入重复的值,则会在您的代码中出现错误.

但是,如果我没记错,可以在Access中使用自动编号列.
Further to Slacker007''s answer

If you enter duplicate values in a Primary Key column it will through an error in your code.

But if I remember rightly in Access you can use a autonumber column.


这篇关于需要VB.NET代码来验证输入的数据并保存在Access 2003数据库中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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