使用一个参数调用SQL存储过程的小页面,用户将在文本框中输入该参数。在声明该参数时,它给出了上述错误。有人可以帮忙吗?错误发生在CMD.Parameters线上..
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim CMD As New SqlCommand("daily_revenue_rerun")
CMD.Parameters("@date", SqlDbType.DateTime).value = TextBox1.Text
Dim connection As SqlConnection = New SqlConnection
connection.ConnectionString = "Data Source=azda-sql0;Persist Security Info=True;User ID=sa;Password=Sql@dm!n;Initial Catalog=RevenueTrakSQL"
CMD.Connection = connection
CMD.CommandType = CommandType.StoredProcedure
Dim Adapter As New SqlDataAdapter(CMD)
Dim DS As DataSet
Adapter.Fill(DS)
connection.Close()
End Sub
感谢您的帮助..
答案 0 :(得分:1)
查看参数绑定。我可以看到你的存储过程daily_revenue_rerun
需要一个DATETIME
数据类型变量,而你传递一个字符串
CMD.Parameters("@date", SqlDbType.DateTime).value = TextBox1.Text