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
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