我正在尝试在vb.net中创建一些将参数传递给SQL Server 2008中的存储过程的应用程序 我试过这段代码,我不确定下一步应该写什么
Public Function List(ByVal date As Date) As DataTable
Dim SPName As String = "usp_Name"
Dim dt As New DataTable
Try
oConn.Open()
Dim cmdSQL As New SqlCommand(SPName, oConn)
cmdSQL.CommandTimeout = 2000
cmdSQL.CommandType = CommandType.StoredProcedure
cmdSQL.Parameters.Add("@Date").Value = date //im not really sure this is the correct code
Dim da As New SqlDataAdapter(cmdSQL)
da.Fill(dt)
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
oConn.Close()
End Try
Return dt
End Function
答案 0 :(得分:1)
使用此代码
cmdSQL .Parameters.AddWithValue("@Date", date)
答案 1 :(得分:1)
应该是
cmdSQL.Parameters.AddWithValue("@Date", date)