RE: Adding a Row With an AutoIncrement Field
- From: davidsc@xxxxxxxxxxxxxxxxxxxx (David Sceppa)
- Date: Tue, 31 May 2005 16:20:06 GMT
Phil,
You want to omit the auto-increment column from the list of values
you're supplying when adding the new row. In VB.NET, use the Nothing
keyword. C# developers would use null. Your code will look something like:
Dim tbl As New DataTable
With tbl.Columns.Add("ID", GetType(Integer))
.AutoIncrement = True
.AutoIncrementSeed = -1
.AutoIncrementStep = -1
End With
tbl.Columns.Add("OtherColumn", GetType(String))
tbl.Rows.Add(New Object() {Nothing, "First row"})
tbl.Rows.Add(New Object() {Nothing, "Second row"})
Console.WriteLine(tbl.Rows(0)("ID"))
Console.WriteLine(tbl.Rows(1)("ID"))
I hope this information proves helpful.
David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2005 Microsoft Corporation. All rights reserved.
.
- References:
- Adding a Row With an AutoIncrement Field
- From: Phil Galey
- Adding a Row With an AutoIncrement Field
- Prev by Date: Re: SQLParameter Bug?
- Next by Date: Re: Timeout on dataAdapter Update method
- Previous by thread: Re: Adding a Row With an AutoIncrement Field
- Next by thread: ado and ado.net dissimilarities
- Index(es):