Transactions with generated DataAdapters

  • Thread starter Steffen.Schlachter
  • Start date
S

Steffen.Schlachter

Hello,

I have generated a DataSet with Visual Studio 2005 by selecting Data ->
Add New Data Source ... -> Database etc. from the menu and selected 2
objects (tables) in the Data Source Configuration Wizard. As a result I
get an .XSD DataSet file that automatically generated a DataAdapter.

I have added an insert statement to both tables.

Question 1: One table has an autonumber id field that automatically
generates a primary key when inserting a new row into the database. How
do I get that automatically primary key which I need for the insert
statement in the second table?

Question 2: Both insert statements should be performed in one
transaction. How do I set up a business method for inserting values
into both tables that executes both insert statements in one
transaction, i.e.

public void insertValues() {

MyFirstDataSet.MyFirstDataAdapter a1 = new
MyFirstDataSet.MyFirstDataAdapter ();
MySecondDataSet.MySecondDataAdapter a2 = new
MySecondDataSet.MySecondDataAdapter ();

// start transaction
a1.InsertValues("mike", "miller");
// a value is inserted into a table with autogenerated primary key
int key = ...
a2.InsertValues(key, "test");
// end transaction or rollback
}

Any help would be much appreciated.

Steffen
 
R

Radenko Zec

Q1:probobly you need in Sql server specify identity seed yes on primary key
or in code make procedure that automatic insert value in primary key column.
Q2:You can use try and catch or begin transaction,roolback transaction?
 

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