[Solved] How to pass parameters to SqlDataAdapter


here is an example of what you can use and how to pass Parameters
you have to make the changes where necessary

Public Shared Function GetCustomerInfo(stardate As DateTime, enddate As DateTime, Department As String, Active as String, Visits as Int33) As List(Of String)
    Dim cszList = New List(Of String)()
    Dim DSCityStateZipLookup As New DataSet()
    'load the List one time to be used thru out the intire application
    Dim ConnString = System.Configuration.ConfigurationManager.ConnectionStrings("CMSConnectionString").ConnectionString
    Using connStr As New SqlConnection(ConnString)
        Using cmd As New SqlCommand("your Stored Proc name goes here", connStr)
            cmd.Parameters.AddWithValue("@stardate", stardate)//make sure you assign a value to startdate
            cmd.Parameters.AddWithValue("@enddate", enddate)//make sure you assign a value to enddate
            cmd.Parameters.AddWithValue("@Deparment", Deparment)//make sure you assign a value to //Department
            cmd.Parameters.AddWithValue("@Active", Active)//make sure you assign a value to Active
            cmd.Parameters.AddWithValue("@Visits", Visits)//make sure you assign a value to Visits
            cmd.Connection.Open()
            New SqlDataAdapter(cmd).Fill(DSCityStateZipLookup)
            'If we get a record back from the above stored procedure call, that in itself means the information the user provided from
            'the UI is in the database. On the other hand, if we do not get a record back from the stored procedure call, we should
            'simply advise the user that the information they provided does not exist in the database, and to double check their spelling.
            If DSCityStateZipLookup.Tables.Count = 0 OrElse (DSCityStateZipLookup.Tables.Count > 0 AndAlso DSCityStateZipLookup.Tables(0).Rows.Count = 0) Then
                cszList.Add("Your Error Message goes here if any.")
            End If
        End Using
    End Using
    Return cszList
End Function

12

solved How to pass parameters to SqlDataAdapter