Cor, the below code is what I'm talking about. I would have thought I should
get an error when I set the AutoIncrement Column 1 to the random integer.
Private Function CreateDataTable(ByVal TableName As String) As DataTable
'Create DataTable and add Columns
Dim t As DataTable = New DataTable
t.TableName = TableName
Dim col1 As DataColumn = New DataColumn("Col1",
Type.GetType("System.Int32"))
Dim col2 As DataColumn = New DataColumn("Col2",
Type.GetType("System.String"))
col1.AutoIncrement = True
'Add DataColumns to DataTable
t.Columns.Add(col1)
t.Columns.Add(col2)
'Populate the Columns
Dim irand As New Random(123)
Dim k as integer
For i = 1 To 25
k = irand.Next
newrow = t.NewRow
newrow("col1") = CType(k, Int32) 'AutoIncrement
newrow("col2") = "ABCD" 'String
t.Rows.Add(newrow)
Next i
End Sub
"Cor Ligthert" wrote:
> Dennis,
>
> I even do not believe you can add numbers to that. However the last
> statement in your message is right.
>
> "Dennis" <(E-Mail Removed)>
>
> > If I understand you correctly, I can add numbers to an AutoIncrement
> > Column
> > in a talbe in a DataSet but when the actual database is updated, the
> > numbers
> > I added won't appear in the Database...is this correct?
> >
> > "Cor Ligthert" wrote:
> >
> >> Dennis,
> >>
> >> I think that you can the best ave a look at this
> >>
> >> autoincrement class
> >> http://msdn.microsoft.com/library/de...ementtopic.asp
> >>
> >> You cannot set the values, they will not even been in the database.
> >> Setting the seed to -1 is the advised method.
> >>
> >> See for this as well the article of Bill
> >> http://msdn.microsoft.com/library/de...anidcrisis.asp
> >>
> >> I hope this helps?
> >>
> >> Cor
> >>
> >> "Dennis" <(E-Mail Removed)>
> >> >I have set a DataTable and one of the columns I set "AutoIncrement" to
> >> >True.
> >> > I then populate the Table by setting the columns to values then add the
> >> > row
> >> > to the table. I inadverently set the AutoIncrement Columns to
> >> > different
> >> > values but didn't get any errors. Should I be able to set the value of
> >> > an
> >> > AutoIncrement Column? I would have thought it couldn't be done as the
> >> > column
> >> > value was set when a row was added.
> >> > --
> >> > Dennis in Houston
> >>
> >>
> >>
>
>
>