Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataReader with two queries

Status
Not open for further replies.

ofsouto

Programmer
Apr 29, 2000
185
BR
I want to use datareader do execute two queries but I need to read the second query first.
Is it possibel to get it using datareader?

the first query execute a stored procedure that insert rows on a table then the second query must get total of some fields.

Dim cnn As New SqlConnection(Global.GetConnectionString)
Dim cmd As New SqlCommand()
Dim dr As SqlDataReader
cnn.Open()

cmd.CommandText = "execute procedure;
select sum(field_1), sum(field_2) from table_1"

cmd.Connection = cnn
dr = cmd.ExecuteReader

Thank you very much

Ofsouto
 
An SqlCommand can contain more than one query as long as it's all within the same batch (like a stored procedure.) Your DataReader will read the result set that is returned by the last SELECT statement in the batch. So, to answer your question, yes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top