[thelist] Filling a dataset from a dynamic SelectCommand?

Casey Crookston caseyc at IntelliSoftmn.com
Tue Aug 22 13:24:41 CDT 2006


Jason  - After I sent the email and went to lunch, I thought that
someone would reply just as you did.  My bad for not being more clear.

If I bind the datagrid with DataGridResults.DataSource =
cmdResults.ExecuteREader() then it works fine with the existing CASE
SELECT statements.  Trouble is, I need a dataset for paging.

Casey

-----Original Message-----

Hi Casey,


Your select case statement should trap the case where
ViewState("SearchType") is something other than the two options you've
given (using "Case Else"). My guess is that some other value is
occurring and consequently your variable isn't being set.

Jason

> -----Original Message-----
?
> 
> 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?






More information about the thelist mailing list