2

I'm trying to create some application in vb.net that passing parameter to stored procedure in SQL server 2008 I've tried this code, and I'm not sure what should I write next

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

2 Answers 2

1

It should be

cmdSQL.Parameters.AddWithValue("@Date", date)
Sign up to request clarification or add additional context in comments.

Comments

1

use this code

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.