Filling a dataset with a stored proc

G

Guest

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:
 
G

Guest

Hi Ant,

you can use

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

HTH

Elton Wang
 
G

Guest

Thank you Elton, that works fine!

Ant

Elton W said:
Hi Ant,

you can use

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

HTH

Elton Wang


Ant said:
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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top