我正在使用以下SQL语句:
Dim strSql5 As String = "SELECT * FROM dbo.ontledings " & _
" where plaasblok = @plaasblokparsversoeke " & _
" and analisedatum = @laastedatum"
cnn.Open()
Dim aksie2 As New SqlClient.SqlCommand(strSql5, cnn)
aksie2.Parameters.Add("@plaasblokparsversoeke", SqlDbType.VarChar).Value = plaasblokparsversoeke
aksie2.Parameters.Add("@laastedatum", SqlDbType.Date).Value = laastedatum
aksie2.ExecuteNonQuery()
cnn.Close()
我想像这样填充数据表:
Dim dtb5 As New DataTable
dtb5.Clear()
Using cnn As New SqlConnection("Data Source=GIDEON-E-LAPTOP\SQLEXPRESS2014;Initial Catalog=SkeduleringDatabasis;Integrated Security=True")
cnn.Open()
Using dad5 As New SqlDataAdapter(strSql5, cnn)
dad5.Fill(dtb5)
End Using
cnn.Close()
End Using
我收到以下错误消息:必须声明标量变量“@plaasblokparsversoeke”
我无法弄清楚在何处以及如何声明标量变量。
错误发生在以下行:dad5.Fill(dtb5)
问候
答案 0 :(得分:5)
您需要添加
等参数MyServiceMock
如下面正确评论,您需要使用Add method添加参数:
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@plaasblokparsversoeke", plaasblokparsversoeke.Text)
cmd.Parameters.AddWithValue("@laastedatum", laastedatum.Text)
答案 1 :(得分:1)
答案 2 :(得分:1)
使用此查询
Dim strSql5 As String = "SELECT * FROM dbo.ontledings " & _
" where plaasblok = @plaasblokparsversoeke " & _
" and analisedatum = @laastedatum"
您正在定义2个名为@plaasblokparsversoeke和@laastedatum的SQL变量,您必须将其作为参数传递给您的命令,例如
command.Parameters.Add("@plaasblokparsversoeke", SqlDbType.Int);
command.Parameters["@plaasblokparsversoeke "].Value = yourValue;
MSDN关于SQL命令参数的文章here