Home All Groups Group Topic Archive Search About

Filling a dataset with a stored proc

Author
7 Feb 2006 10:08 PM
Ant
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:

Author
7 Feb 2006 11:18 PM
Elton W
Hi Ant,

you can use

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

HTH

Elton Wang


Show quote
"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:
>
>
Author
8 Feb 2006 1:21 AM
Ant
Thank you Elton, that works fine!

Ant

Show quote
"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:
> >
> >

AddThis Social Bookmark Button