Executing Mulitiple Queries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I execute two queries with in a single Command.text.

Like in first query I want to insert a row and in second query I want to get
the RowId last inserted.

or do I have to execute two queries?

Thnx
 
It depends on your database... some implementations don't support batch
queries. But for Sql Server or Oracle for instance, you can definitely
batch up the commands and fire them. If you fill a dataSet for instance,
each select query will populate a different table within the dataset and you
use TableMappings to specify how that happens. Similiarly, if you use a
DataReader, you can use while(reader.Read()){

} to walk through your reader, but if you have multiple select statements,
you can wrap the while (reader.Read()) inside a do { } while
reader.NextResult() to walk through the next query.

As far as your specific scenario - go to www.betav.com -> Articles -> MSDN .
The illustrious Mr Vaughn has two articles on the matter - Managing an
@@Identity Crisis and Retrieving the Gozoutas that I can assure you, you'll
find enlightening and speak directly to the issue you ask about. The short
answer though is that you can use another Sql Statement (that's actually
what the data Adapter Configuration Wizard does if you select the Refresh
DataSet option) or you can use an OutPut Parameter for instance. His
articles describe both in detail.

Cheers,

Bill
 
You seem to be one step ahead of me (again)... ;)

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top