PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Filling a dataset with a stored proc

Reply

Filling a dataset with a stored proc

 
Thread Tools Rate Thread
Old 07-02-2006, 10:08 PM   #1
=?Utf-8?B?QW50?=
Guest
 
Posts: n/a
Default Filling a dataset with a stored proc


Hi,
I'm returning rows from a search done using a sp & one input parameter.
Therefore I am using a command to return the result set. These need to go
into a dataset in order for it to be bound to a data grid. I received two
ways to do it from this discussion group but neither work for me. The First
was directly from the command object to the dataset, as below:

dsResults.Tables["resultTable"] = comSearchByName.ExecuteReader();
// didn't work

The second was via a DataAdapter, as below, except the example i was given
used a string instead of a command. I want to use a command:

SqlDataAdapter da = new SqlDataAdapter(comSearchByName,sqlConnection1);

but received an error:
Cannot convert from System.Data.SqlClient.SQLCommand to string

I would prefer not to use a data Adapter & do it straight from the command
if possible, but if this is not possible, how do I use the data Adapter
without raising the specified error?

Hope someone can help out
Thanks in advance
Ant




SqlDataAdapter da = new SqlDataAdapter(comSearchByName,sqlConnection1);

however, this creates the error below:


  Reply With Quote
Old 07-02-2006, 11:18 PM   #2
=?Utf-8?B?RWx0b24gVw==?=
Guest
 
Posts: n/a
Default RE: Filling a dataset with a stored proc

Hi Ant,

you can use

System.Data.SqlClient.SqlDataAdapter dap = new
System.Data.SqlClient.SqlDataAdapter(SqlCommandObj);

HTH

Elton Wang


"Ant" wrote:

> Hi,
> I'm returning rows from a search done using a sp & one input parameter.
> Therefore I am using a command to return the result set. These need to go
> into a dataset in order for it to be bound to a data grid. I received two
> ways to do it from this discussion group but neither work for me. The First
> was directly from the command object to the dataset, as below:
>
> dsResults.Tables["resultTable"] = comSearchByName.ExecuteReader();
> // didn't work
>
> The second was via a DataAdapter, as below, except the example i was given
> used a string instead of a command. I want to use a command:
>
> SqlDataAdapter da = new SqlDataAdapter(comSearchByName,sqlConnection1);
>
> but received an error:
> Cannot convert from System.Data.SqlClient.SQLCommand to string
>
> I would prefer not to use a data Adapter & do it straight from the command
> if possible, but if this is not possible, how do I use the data Adapter
> without raising the specified error?
>
> Hope someone can help out
> Thanks in advance
> Ant
>
>
>
>
> SqlDataAdapter da = new SqlDataAdapter(comSearchByName,sqlConnection1);
>
> however, this creates the error below:
>
>

  Reply With Quote
Old 08-02-2006, 01:21 AM   #3
=?Utf-8?B?QW50?=
Guest
 
Posts: n/a
Default RE: Filling a dataset with a stored proc

Thank you Elton, that works fine!

Ant

"Elton W" wrote:

> Hi Ant,
>
> you can use
>
> System.Data.SqlClient.SqlDataAdapter dap = new
> System.Data.SqlClient.SqlDataAdapter(SqlCommandObj);
>
> HTH
>
> Elton Wang
>
>
> "Ant" wrote:
>
> > Hi,
> > I'm returning rows from a search done using a sp & one input parameter.
> > Therefore I am using a command to return the result set. These need to go
> > into a dataset in order for it to be bound to a data grid. I received two
> > ways to do it from this discussion group but neither work for me. The First
> > was directly from the command object to the dataset, as below:
> >
> > dsResults.Tables["resultTable"] = comSearchByName.ExecuteReader();
> > // didn't work
> >
> > The second was via a DataAdapter, as below, except the example i was given
> > used a string instead of a command. I want to use a command:
> >
> > SqlDataAdapter da = new SqlDataAdapter(comSearchByName,sqlConnection1);
> >
> > but received an error:
> > Cannot convert from System.Data.SqlClient.SQLCommand to string
> >
> > I would prefer not to use a data Adapter & do it straight from the command
> > if possible, but if this is not possible, how do I use the data Adapter
> > without raising the specified error?
> >
> > Hope someone can help out
> > Thanks in advance
> > Ant
> >
> >
> >
> >
> > SqlDataAdapter da = new SqlDataAdapter(comSearchByName,sqlConnection1);
> >
> > however, this creates the error below:
> >
> >

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off