[thelist] Filling a dataset from a dynamic SelectCommand?

Tab Alleman talleman at Lumpsum.com
Tue Aug 22 12:59:35 CDT 2006


I think, for one thing, that you need to change this:

Dim dadListings As SqlDataAdapter

to this:


Dim dadListings As New SqlDataAdapter



> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of Casey Crookston
> Sent: Tuesday, August 22, 2006 1:25 PM
> 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