【发布时间】:2018-07-17 14:41:08
【问题描述】:
我正在 VB.NET 中开发一个桌面应用程序,我想在其中编辑、删除和添加 DataGridView 中的新行。我怎样才能做到这一点?
出现错误“从字符串“Update dbo.Trans set BCode='1'”转换为“Double”类型无效。”
我试过的代码:
con = New SqlConnection("Data Source=USER\SQLEXPRESS;Initial Catalog=Sap;Integrated Security=True")
If (TbCode.Text = "" Or TbItem.Text = "" Or TbWgt.Text = "") Then
MessageBox.Show("Please fill all the columns")
Else
con.Open()
cmd1 = New SqlCommand("Update dbo.Trans set BCode='" + TbCode.Text + "',BName='" + Label2.Text + "',ICode='" + TbItem.Text + "',IName='" + Label3.Text + "',Qty='" + TbQty.Text + "',Weight='" + TbWgt.Text + "',RWeight='" + Label4.Text + "',Rate='" + Rate + "' where date=@date and depot=@depot and BCode=@bcode and Icode=@icode", con)
cmd1.Parameters.AddWithValue("@depot", TbDepot.Text)
cmd1.Parameters.AddWithValue("@icode", TbItem.Text)
cmd1.Parameters.AddWithValue("@date", IDate.Text)
cmd1.Parameters.AddWithValue("@bcode", TbCode.Text)
cmd1.ExecuteNonQuery()
End If
con.Close()
Call Fillgrid()
Call emptyfun()
End Sub
【问题讨论】:
-
id1 应该是您在 SQL 语句中想要的吗?因为你有身份证。为什么不使用 Date 和 Depot 那样的参数?您是否收到任何错误消息?缺少很多代码来正确设置和执行该 SqlCommand。
-
先生,我尝试使用此代码通过检索文本框中的值来更新网格值。
-
你的 Trans 表有主键吗?