By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,696 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,696 IT Pros & Developers. It's quick & easy.

DataTable.NewRow problem

P: n/a
Hi All

I have a DataTable that has the AutoIncrement properties set, but when I add
a new row it doesn't use the values I'd expect and is causing an error.

For example:

MyTable.Columns("PKColumn").AutoIncrement = True
MyTable.Columns("PKColumn").AutoIncrementSeed = -1
MyTable.Columns("PKColumn").AutoIncrementStep = -1

Dim oRow As DataRow = MyTable.NewRow
'// oRow("PKColumn") = 12 I'd expect it to be a negative figure, and for
each Row I add it decreases by 1
MyTable.Rows.Add(oRow) '// Causes error the second row that's added cos the
PK value already exists amd is unique.

Has anyone else experience this??

Regards,
Steve.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If you have statement like MyDataAdapter.FillSchema(MyDataSet,
SchemaType.Mapped, "MyTable") running before, you cannot change PKColumn's
property in MyTable.

"Steve Amey" wrote:
Hi All

I have a DataTable that has the AutoIncrement properties set, but when I add
a new row it doesn't use the values I'd expect and is causing an error.

For example:

MyTable.Columns("PKColumn").AutoIncrement = True
MyTable.Columns("PKColumn").AutoIncrementSeed = -1
MyTable.Columns("PKColumn").AutoIncrementStep = -1

Dim oRow As DataRow = MyTable.NewRow
'// oRow("PKColumn") = 12 I'd expect it to be a negative figure, and for
each Row I add it decreases by 1
MyTable.Rows.Add(oRow) '// Causes error the second row that's added cos the
PK value already exists amd is unique.

Has anyone else experience this??

Regards,
Steve.

Nov 21 '05 #2

P: n/a
Hi John

I don't have anything like that running before I can see the properties of
the Column in the Locals window and they are correct, but when I create a
New Row it doesn't create the row with the PK column as a negative.

Regards,
Steve.

"John" <Jo**@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
If you have statement like MyDataAdapter.FillSchema(MyDataSet,
SchemaType.Mapped, "MyTable") running before, you cannot change PKColumn's
property in MyTable.

"Steve Amey" wrote:
Hi All

I have a DataTable that has the AutoIncrement properties set, but when I add a new row it doesn't use the values I'd expect and is causing an error.

For example:

MyTable.Columns("PKColumn").AutoIncrement = True
MyTable.Columns("PKColumn").AutoIncrementSeed = -1
MyTable.Columns("PKColumn").AutoIncrementStep = -1

Dim oRow As DataRow = MyTable.NewRow
'// oRow("PKColumn") = 12 I'd expect it to be a negative figure, and for
each Row I add it decreases by 1
MyTable.Rows.Add(oRow) '// Causes error the second row that's added cos the PK value already exists amd is unique.

Has anyone else experience this??

Regards,
Steve.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.