本文介绍了删除表中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小型vb.net项目.当我删除
按名称记录显示错误消息,例如
这个"

i create small vb.net project. when i delete
record by name display erro message like
this "

system.data.sqlclient.sqlexception:invalid
column name ''jak''. at system .data.........


但实际上"jak"和他的信息已保存
在桌子上.然后我尝试通过
删除他的信息他的年龄.它的工作.但我不知道
按名称删除信息.我的代码是


but actualy ''jak'' and his infomation saved
in table. then i try delete his infomation by
his age. its worked. but i have no idea
delete infomation by names. my code is

try
Dim del As new sqlcomand("DELETE FROM
members WHERE name="& textbox1.text
& "", dbcon)
dbconn.open()
del.execuenonquery()
dbconn.close()
Catch ex as Exception
Msgbox(ex.tostring)
end try


它是corect吗?
请朋友帮我.我正在使用vb.net
和SQL服务器.表名是成员.有两个领域.其名称(文字)和年龄(int)
谢谢.


is it corect??
please friends help me. I''m using vb.net
and sql server. table name is members. there have two fields. its name(text) and age(int)
thank you.

推荐答案

Dim del As new SqlCommand("DELETE FROM members WHERE name=@NM", dbcon)
del.Parameters.AddWithValue("@NM", textbox1.Text)



其次,您可能会发现问题也消失了!



Secondly, you may find your problem disappears as well!



Dim del As new SqlCommand("DELETE FROM members WHERE name=@NM", dbcon)
del.Parameters.AddWithValue("@NM", textbox1.Text)





or

Dim del As new sqlcomand("DELETE FROM
members WHERE name='"& textbox1.text
& "'", dbcon)


这篇关于删除表中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:48