dataset, datatable, dataadapter

  • Thread starter Thread starter DaveP
  • Start date Start date
D

DaveP

is it possible to send one command and return multiple record sets
instead of creating 3 separate command objects
and executing them independently

Tia
DaveP
 
is it possible to send one command and return multiple record sets
instead of creating 3 separate command objects
and executing them independently

Tia
DaveP

Yep. Make the command a transact sql batch. You can move to the next
resultset with the DataReader.NextResult() method (assuming you're
using the SqlClient).
 
is it possible to send one command and return multiple record sets
instead of creating 3 separate command objects
and executing them independently

Tia
DaveP

If you were connecting to the sample pubs database, you could return 2
resultsets w/ the following:

SqlCommand cmd = conn.CreateCommand();

cmd.CommandText = @"BEGIN
select * from authors
select * from titles
END";

try
{
conn.Open();

SqlDataReader rdr = cmd.ExecuteReader();

while ( rdr.Read() )
Console.WriteLine("author={0} {1}", rdr["au_fname"],
rdr["au_lname"]);

rdr.NextResult();

while ( rdr.Read() )
Console.WriteLine("title={0}", rdr["title"]);

rdr.Close();
}
catch
{ // do whatever here....
}
finally
{
conn.Close();
}
 
Hi,


DaveP said:
is it possible to send one command and return multiple record sets
instead of creating 3 separate command objects
and executing them independently

Yes, just put more than one SELECT statement in the query
 
thanks for the Sample

Arnshea said:
is it possible to send one command and return multiple record sets
instead of creating 3 separate command objects
and executing them independently

Tia
DaveP

If you were connecting to the sample pubs database, you could return 2
resultsets w/ the following:

SqlCommand cmd = conn.CreateCommand();

cmd.CommandText = @"BEGIN
select * from authors
select * from titles
END";

try
{
conn.Open();

SqlDataReader rdr = cmd.ExecuteReader();

while ( rdr.Read() )
Console.WriteLine("author={0} {1}", rdr["au_fname"],
rdr["au_lname"]);

rdr.NextResult();

while ( rdr.Read() )
Console.WriteLine("title={0}", rdr["title"]);

rdr.Close();
}
catch
{ // do whatever here....
}
finally
{
conn.Close();
}
 

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

Back
Top