使用存储的过程从vb.net传递参数

问题描述 投票:2回答:2

我试图创建在参数传递到存储过程中的SQL服务器vb.net一些应用程序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
sql-server vb.net sql-server-2008
2个回答
1
投票

它应该是

cmdSQL.Parameters.AddWithValue("@Date", date)

1
投票

使用此代码

cmdSQL .Parameters.AddWithValue("@Date", date)
© www.soinside.com 2019 - 2024. All rights reserved.