N
Nader Soliman
I just thought I should share this with you guys:
This an investigation that I conducted the problem of
System.Data.ConstraintException: Column 'XYZ' is constrained to be
unique. Value '1' is already present.
When trying to use SqlDataAdapter to insert a bunch of rows from a
dataset.
The problem was on one database my insert statement worked just fine on
another database it was not working fine and always gave the above
exception.
I usually build my adapters manually and here is what I use
_DBAdapter.InsertCommand = new SqlCommand();
_DBAdapter.InsertCommand.Connection = Connection;
_DBAdapter.InsertCommand.CommandText = @"INSERT INTO tblABC
([XYZ]) VALUES (@xyz,);
SELECT * FROM tblABC WHERE ([ID] = SCOPE_IDENTITY());"
// Rest of code is just the parameters.
The cause of the problem was that my customer usually used "TRUNCATE
TABLE tblABC" which somehow missed with the Identity column (possible
reset the seed or something which has broken an assumption in ADO.NET
dataset ... please MS Guys confirm this).
Now I thought yes ... that might be the UpdateRowSource problem so I
added this line
_DBAdapter.InsertCommand.UpdatedRowSource =
UpdateRowSource.FirstReturnedRecord;
With no avail ... take a look at this URL for a confirmation of this
problem
(http://www.dotnetfun.com/articles/winforms/DataGridIdentityConflictSQLServer.aspx?aid=8)
So I decided to set AutoIncrementSeed and AutoIncrementStep as
indicated by
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/manidcrisis.asp)
I set them in the DataSet schema file as msdata:AutoIncrementSeed="-1"
msdata:AutoIncrementStep="-1" and voila everything is working fine.
Finally, MS Guys out there could explain that bug?
Read this link for some other reports of the problem
http://groups-beta.google.com/group...449b6/24235e15b88392a4?hl=en#24235e15b88392a4
Nader O. Soliman
Freelance Software Engineer
Web & Desktop Development
This an investigation that I conducted the problem of
System.Data.ConstraintException: Column 'XYZ' is constrained to be
unique. Value '1' is already present.
When trying to use SqlDataAdapter to insert a bunch of rows from a
dataset.
The problem was on one database my insert statement worked just fine on
another database it was not working fine and always gave the above
exception.
I usually build my adapters manually and here is what I use
_DBAdapter.InsertCommand = new SqlCommand();
_DBAdapter.InsertCommand.Connection = Connection;
_DBAdapter.InsertCommand.CommandText = @"INSERT INTO tblABC
([XYZ]) VALUES (@xyz,);
SELECT * FROM tblABC WHERE ([ID] = SCOPE_IDENTITY());"
// Rest of code is just the parameters.
The cause of the problem was that my customer usually used "TRUNCATE
TABLE tblABC" which somehow missed with the Identity column (possible
reset the seed or something which has broken an assumption in ADO.NET
dataset ... please MS Guys confirm this).
Now I thought yes ... that might be the UpdateRowSource problem so I
added this line
_DBAdapter.InsertCommand.UpdatedRowSource =
UpdateRowSource.FirstReturnedRecord;
With no avail ... take a look at this URL for a confirmation of this
problem
(http://www.dotnetfun.com/articles/winforms/DataGridIdentityConflictSQLServer.aspx?aid=8)
So I decided to set AutoIncrementSeed and AutoIncrementStep as
indicated by
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/manidcrisis.asp)
I set them in the DataSet schema file as msdata:AutoIncrementSeed="-1"
msdata:AutoIncrementStep="-1" and voila everything is working fine.
Finally, MS Guys out there could explain that bug?
Read this link for some other reports of the problem
http://groups-beta.google.com/group...449b6/24235e15b88392a4?hl=en#24235e15b88392a4
Nader O. Soliman
Freelance Software Engineer
Web & Desktop Development