Usefula ADO.NET article:
http://msdn.microsoft.com/library/de...adonetbest.asp
Excerpt from above article:
Avoiding Auto-Increment Value Conflicts
Like most data sources, the DataSet enables you to identify columns that
automatically increment their value when new rows are added. When using
auto-increment columns in a DataSet, with auto-increment columns from a data
source, avoid conflicts between the local numbering of rows added to the
DataSet and rows added to the data source.
For example, consider a table with an auto-incrementing primary key column
of CustomerID. Two new rows of customer information are added to the table
and receive auto-incremented CustomerID values of 1 and 2. Then, only the
second customer row is passed to the Update method of the DataAdapter, the
newly added row receives an auto-incremented CustomerID value of 1 at the
data source, which does not match the value 2, in the DataSet. When the
DataAdapter fills the second row in the table with the returned value, a
constraint violation occurs because the first customer row already has a
CustomerID of 1.
To avoid this behavior, it is recommended that, when working with
auto-incrementing columns at a data source and auto-incrementing columns in a
DataSet, you create the column in the DataSet with an AutoIncrementStep of -1
and an AutoIncrementSeed of 0, as well as ensuring that your data source
generates auto-incrementing identity values starting from 1 and incrementing
with a positive step value. As a result, the DataSet generates negative
numbers for auto-incremented values that do not conflict with the positive
auto-increment values generated by the data source. Another option is to use
columns of type Guid instead of auto-incrementing columns. The algorithm that
generates Guid values should never generate the same Guid in the DataSet as
is generated by the data source.
If your auto-incremented column is used simply as a unique value, and does
not have any meaning, consider using Guids instead of auto-incrementing
columns. They are unique and avoid the extra work necessary to work with
auto-incremented columns.
"Alpha" wrote:
I retrieve a table with only 2 columns. One is a auto-generated primary key
column and the 2nd is a string. When I add a new row to the dataset to be
updated back to the database. What should I do with the 1st column ? (Below
I have a "1" in place for now). Also, Does the datase.AcceptChanges();
updates the changes to the database? Which command do I use to update the
changes in dataset back to the Access database table? Thanks, Alpha
dtSI.Rows.Add(new Object[] {1, txtNewitem.Text});
dsServiceItems1.AcceptChanges();