应在其中插入数据的字段实际上取决于当前处于活动状态的商店。出于这个原因,我希望参数根据情况是动态的,但是我无法弄清楚如何在Parameter函数中提及变量作为字段名称
代码:
Dim whichListID = "Store1ListID"
Str = "Insert Into Customer ([" & whichListID & "], [AccountBalance])"&
"Values(@" & whichListID & ",@AccountBalance)"
cmd = New SqlCommand(Str, con2) 'Fine up till here
cmd.Parameters.AddWithValue("" & "@" & whichListID & "", "45675671")
cmd.Parameters.AddWithValue("@AccountBalance", 0)
con2.Open()
cmd.ExecuteNonQuery()
con2.Close()
所以我的问题是如何正确编写以下语句:-
cmd.Parameters.AddWithValue("" & "@" & whichListID & "", "45675671")
答案 0 :(得分:-1)
我输入了以下代码来解决问题
Dim Param As String="@" & WhichListID
cmd.Parameters.AddWithValue(Param , "45675671")