从VB.Net中的SQL表中删除记录 [英] Delete records from SQL table in VB.Net
本文介绍了从VB.Net中的SQL表中删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
我试图从我的表中删除记录但是无法这样做。我有窗体,包含插入,更新,删除和保存按钮。我可以插入数据,但我不能删除该表中的特定或任何记录。以下是我的代码。
每当我点击''删除''按钮时,我得到(删除表上的记录时出错...& ex.Message,删除记录)仅限msgbox。
我错过了什么吗?请指教。任何帮助都会很棒。谢谢!
Hello Friends,
I am trying to delete records from my table but unable to do so. I have window form with Insert, Update, Delete and Save button. I can insert data but I can''t delete specific or any records from that table. Below is my code.
Whenever I click ''delete'' button I get ("Error while deleting record on table..." & ex.Message, "Delete Records") msgbox only.
Am I missing something? Please advise. Any help would be great. Thank you!
Private Sub Deletebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Deletebtn.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Server=USRAG-L-0067215\SQLEXPRESS;Database=Alamo Products_Design Data;Trusted_Connection=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "Delete From Design_ParameterswhereDesignID=@DesignID "
cmd.Parameters.Add(New SqlParameter("@DesignID", " Am I missing any value here?"))
cmd.ExecuteNonQuery()
If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
MsgBox("Operation Cancelled")
Exit Sub
End If
Catch ex As Exception
MessageBox.Show("Error while deleting record on table..." & ex.Message, "Delete Records")
Finally
con.Close()
End Try
End Sub
End Class
推荐答案
'?''代表你的 CommandText
。如果是未命名参数,请参阅如何设置未命名的SQL参数在SqlCommand [ ^ ]。此外,在您的代码中设置了这样的参数?
What the ''?'' stands for in your CommandText
. If it is an unnamed parameter, please see "How to set unnamed SQL parameters in SqlCommand"[^]. Moreover where such parameter is set in your code?
这篇关于从VB.Net中的SQL表中删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文