SqlAdapter, dataset

  • Thread starter Thread starter Analizer1
  • Start date Start date
A

Analizer1

i have a proc (sql server) i want to send back 3 selects from 1 proc....any
examples of how to do this

Tks
Analizer1
 
Hi
You are refering to calling Execute reader 3 times in a row? or are
you trying to get back 3 selects in the one call?
The first is achievable by closing the reader after you have stashed
all the data, clear the parameters collection and executereader again
etc.

The only way to do the second that I can think of is to use temp
tables in the proc and return the union of their 3 separate select
into statements
hth
Bob
 
Analizer1 said:
i have a proc (sql server) i want to send back 3 selects from 1
proc....any examples of how to do this

The proc:

CREATE PROCEDURE MyProc AS
Select * from Table1
Select * from Table2
Select * from Table3
GO

The code to call it:

SqlCommand cmd = new SqlCommand("MyProc", connection);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//Process results from 1st Select
}
rdr.NextResult();
while (rdr.Read())
{
//Process results from 2nd Select
}
rdr.NextResult();
while (rdr.Read())
{
//Process results from 3rd Select
}
rdr.Close();
 
Alberto Poblacion pisze:
CREATE PROCEDURE MyProc AS
Select * from Table1
Select * from Table2
Select * from Table3
GO

The code to call it:
[...]

Or
SqlCommand cmd = new SqlCommand("MyProc", connection);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);


ds.Tables[0] - result of first select
ds.Tables[1] - result of second select
ds.Tables[3] - result of third select
 
thank you very much

Alberto Poblacion said:
The proc:

CREATE PROCEDURE MyProc AS
Select * from Table1
Select * from Table2
Select * from Table3
GO

The code to call it:

SqlCommand cmd = new SqlCommand("MyProc", connection);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//Process results from 1st Select
}
rdr.NextResult();
while (rdr.Read())
{
//Process results from 2nd Select
}
rdr.NextResult();
while (rdr.Read())
{
//Process results from 3rd Select
}
rdr.Close();
 
Analizer1 said:
i have a proc (sql server) i want to send back 3 selects from 1
proc....any examples of how to do this

Tks
Analizer1
Im selection 19 rows form a table with 173 columns
i want to add them to a table
as you can see from the below the column counts are wrong

I do not know what the problem is
Tks


while (reader.Read())

{

object[] ColumnValues = new Object[reader.FieldCount];

reader.GetValues(ColumnValues);

if (x==0)

{

x = 1;

dtClaims = reader.GetSchemaTable();

}

Console.WriteLine("Table "+dtTest.Columns.Count.ToString());
//shows 30 columns

Console.WriteLine("Reader "+ColumnValues.GetUpperBound(0).ToString()); //
shows 173 which is the correct amount

}
 

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