[thelist] Filling a dataset from a dynamic SelectCommand?

jason.handby jason.handby at corestar.co.uk
Tue Aug 22 12:32:36 CDT 2006


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-----
> From: thelist-bounces at lists.evolt.org 
> [mailto:thelist-bounces at lists.evolt.org] On Behalf Of Casey Crookston
> Sent: 22 August 2006 18:25
> To: thelist at lists.evolt.org
> Subject: [thelist] Filling a dataset from a dynamic SelectCommand?
> 
> 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
> 
>  
> 
> -- 
> 
> * * Please support the community that supports you.  * * 
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip 
> Harvester and archives of thelist go to: 
> http://lists.evolt.org Workers of the Web, evolt ! 
> 



More information about the thelist mailing list