[thelist] Filling a dataset from a dynamic SelectCommand?
Casey Crookston
caseyc at IntelliSoftmn.com
Tue Aug 22 12:24:46 CDT 2006
I'm having trouble filling a dataset. The code below (simplified)
complies with no errors,
but at runtime this line errors out: dadListings.SelectCommand =
cmdResults
Object reference not set to an instance of an object
Dim cmdResults As SqlCommand
Dim dstListings As DataSet = New DataSet
Dim dadListings As SqlDataAdapter
Select Case ViewState("SearchType")
Case "name"
cmdResults = New SqlCommand("getSearchName", dbConnect)
cmdResults.CommandType = CommandType.StoredProcedure
cmdResults.Parameters.Add("@search", txtName.Text)
cmdResults.Parameters.Add("@city", drpCity.SelectedItem.Text)
Case "category"
cmdResults = New SqlCommand("getSearchAddress", dbConnect)
cmdResults.CommandType = CommandType.StoredProcedure
cmdResults.Parameters.Add("@category", txtCategory.Text)
End Select
dadListings.SelectCommand = cmdResults
dadListings.Fill(dstListings)
DataGridResults.DataSource = dstListings
DataGridResults.DataBind()
How do I fill the dataset when the query/stored procedure is dynamic?
Thanks!!
Casey
More information about the thelist
mailing list