472,353 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

DataColumn Autoincrement value

Hi:

How to reset the autoincrement value generated by DataTable ?

I've master and detail table, the detail table has a autoincrement
column, each time i add a new master record, i need to reset the
detail table autoincrement column to start from 1.

I set the dataColumn AutoIncrementSeed=0 and AutoIncrementStep=1 each
time i append a new master row, but it seem not work, it still remain
the previous value, any idea ?

Thanks
JCVoon
Nov 21 '05 #1
5 7956
JC,

When the increment is 0 than you would get directly (I thought) a
concurrency vialation error.

Cor
Nov 21 '05 #2
Dim dt As New DataTable

Dim myColumn As DataColumn = New DataColumn("ID")
myColumn.ReadOnly = True
'myColumn.DataType = System.Type.GetType("System.Int32")
myColumn.DataType = GetType(Integer)
With myColumn
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
End With

' Add the column to a new DataTable.
dt.Columns.Add(myColumn)

Dim myKey(0) As DataColumn
myKey(0) = dt.Columns("ID")

dt.PrimaryKey = myKey

HTH,
Greg

"JC Voon" <jc*******@yahoo.com> wrote in message
news:41***************@msnews.microsoft.com...
Hi:

How to reset the autoincrement value generated by DataTable ?

I've master and detail table, the detail table has a autoincrement
column, each time i add a new master record, i need to reset the
detail table autoincrement column to start from 1.

I set the dataColumn AutoIncrementSeed=0 and AutoIncrementStep=1 each
time i append a new master row, but it seem not work, it still remain
the previous value, any idea ?

Thanks
JCVoon

Nov 21 '05 #3
Sorry! I didn't read the question fully.

I assume you detail table has a composite primary key...

MasterKey, DetailKey

100,1
100,2
100,3

101,1
101,2

102,1
102,2
102,3
102,4

etc.

If this was in SQL Server your could write a trigger to determine your
DetailKey value. This starts to get real ugly when you need to later delete
a row or insert in between values. Not sure how to do this using a
datatable.

You maybe better off using a GUID as your DetailKey. (I've had success,
using this strategy)

100, {F6C3B751-59EB-49BF-AE8F-0009097087D8}
100, {9258B3BD-4683-4DBE-822F-000B3757BACB}

101, {E39C2D34-11E4-4645-9921-00130E4AB40E}

etc.

If order is important (I assume it is, hence your desire for the sequential
numbers). You could add a nonkey column that is a timestamp or something.

Greg

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:e%******************@TK2MSFTNGP12.phx.gbl...
Dim dt As New DataTable

Dim myColumn As DataColumn = New DataColumn("ID")
myColumn.ReadOnly = True
'myColumn.DataType = System.Type.GetType("System.Int32")
myColumn.DataType = GetType(Integer)
With myColumn
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
End With

' Add the column to a new DataTable.
dt.Columns.Add(myColumn)

Dim myKey(0) As DataColumn
myKey(0) = dt.Columns("ID")

dt.PrimaryKey = myKey

HTH,
Greg

"JC Voon" <jc*******@yahoo.com> wrote in message
news:41***************@msnews.microsoft.com...
Hi:

How to reset the autoincrement value generated by DataTable ?

I've master and detail table, the detail table has a autoincrement
column, each time i add a new master record, i need to reset the
detail table autoincrement column to start from 1.

I set the dataColumn AutoIncrementSeed=0 and AutoIncrementStep=1 each
time i append a new master row, but it seem not work, it still remain
the previous value, any idea ?

Thanks
JCVoon


Nov 21 '05 #4
Greg Burns, Cor:

Thanks for the reply.
MasterKey, DetailKey

100,1
100,2
100,3

101,1
101,2

102,1
102,2
102,3
102,4
Yes this is exactly what i need
If order is important (I assume it is, hence your desire for the sequential
numbers). You could add a nonkey column that is a timestamp or something.


So it is impossible to reset the autoincrement value ?
Regards
JCVoon
Nov 21 '05 #5
> So it is impossible to reset the autoincrement value ?

AFAIK, it is impossible.

"JC Voon" <jc*******@yahoo.com> wrote in message
news:41**************@msnews.microsoft.com...
Greg Burns, Cor:

Thanks for the reply.
MasterKey, DetailKey

100,1
100,2
100,3

101,1
101,2

102,1
102,2
102,3
102,4


Yes this is exactly what i need
If order is important (I assume it is, hence your desire for the
sequential
numbers). You could add a nonkey column that is a timestamp or something.


So it is impossible to reset the autoincrement value ?
Regards
JCVoon

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jaYPee | last post by:
I have a table in my sqlserver 2000 that has a field IDNO. i want this field to be my primary key. however i don't want this field to use the...
2
by: RA | last post by:
Hi I have the following datarow that I want to add to a datatable. DataRow newRow = ds.Tables.NewRow (); newRow = Cache.ToString (); newRow...
6
by: Dennis | last post by:
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...
1
by: Sam | last post by:
Hi all I have a simple datagrid form which has 4 columns. The first one is used just like a key and the other threes allow user to enter numbers....
6
by: Michael | last post by:
I am trying to create an access database within Net 2003 using the ADOX library which works fine except when I try to add the AutoIncrement property...
3
by: MP | last post by:
context: vb6/ ado / .mdb format / jet 4.0 (not using Access - ADO only) - creating tables via ADO (don't have access) - all tables have a primary...
1
by: Mike | last post by:
I have a form that has an embedded subform (Datasheet View) that are linked based on a 1-many ID field. I have a field (SET) in my embedded...
4
by: Tim | last post by:
Hello All, I could use some help on an error that is just now popping it's head up. Seems that the autoincrement numeric has hit 32,767. The...
0
by: Ryan Liu | last post by:
I have a program works fine in .NET 1.1 and just recompiled in .NET 2.0 without any code change. Compiles OK, but there is an exeception when...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.