`Dim con1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim sql1 As String
sql1 = "Update Balance set Balance_Amt = (Balance_Amt + " & a & ") where Company = " & Combo3.Text
con1.Execute (sql1)
“谁能说出为什么这段代码不起作用?它说一个或多个必需参数没有值”
`Dim con1 As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim sql1 As String
sql1 = "Update Balance set Balance_Amt = (Balance_Amt + " & a & ") where Company = " & Combo3.Text
con1.Execute (sql1)
“谁能说出为什么这段代码不起作用?它说一个或多个必需参数没有值”
我猜直接的问题是 SQL 片段
where Company = value
是无效的 SQL。应该引用:
where Company = 'value'
但是你真的应该使用 SQL 参数。
例如
Using cmd = new SqlCommand("UPDATE Balance SET Balance_Amt = (Balance_Amt + @a) WHERE Company=@company", con1)
cmd.Parameters.AddWithValue("@a", a)
cmd.Parameters.AddWithValue("@company", company)
cmd.ExecuteNonQuery()
End Using
打印出sql语句,看看是否ok,复制/粘贴到sql管理工作室。我认为您在字符串 Combo3.Text 周围缺少撇号。
还要考虑如果 Combo3.Text 包含它会导致什么 sql
'a'; delete from Balance