从数据库删除记录的代码 [英] Code to delete records from database

查看:125
本文介绍了从数据库删除记录的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai,我可以在vb.net中的Windows应用程序窗体中删除数据的编码方法是什么..
我正在使用Visual Studio 2005和sql2005.如果用户单击按钮,则删除其选择的数据.

解决方案

如果要从中删除数据数据库,您首先使用适当的条件选择了数据,然后基本上将条件从select语句转换为delete语句.

因此,例如,如果您选择以下内容:

SELECT * FROM MyTable WHERE SomeField = 1


现在您要删除要使用的那些行

 删除  FROM  MyTable > WHERE  SomeField =  1  


要执行删除,您可以使用 ExecuteNonQuery [ ^ ].

有关删除的更多信息,请参见:删除(Transact-SQL) [ ^ ]

同样好的做法是对值使用绑定变量.请参阅: SqlParameter类 [ 解决方案

If you want to delete the data from the database and you have first selected the data using proper conditions, then you basically transform the conditions from the select statement to a delete statement.

So for example if you have select something like:

SELECT * FROM MyTable WHERE SomeField = 1


and now you want to delete those rows you would use

DELETE FROM MyTable WHERE SomeField = 1


To execute the delete you can use
ExecuteNonQuery[^].

For more information about the delete, see: DELETE (Transact-SQL)[^]

Also a good practice is to use bind variables for values. See: SqlParameter Class[^]


这篇关于从数据库删除记录的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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