473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

DataColumn Class and AutoIncrement

Sam
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. The
problem that I am having is that when I click on a cell of a new row but
decide not to enter a value and go back to any of the previous rows for
editting or whatever reason, the value of the new row will be incremented by
value of the AutoIncrementStep

Here is the problem I have

When I loaded the table for a first time, the first row has a value of 0 in
column 1. I then entered 5, 5, 5 in column 2, 3, and 4 respectively. I
clicked on the 2nd row (new row), a new value of 1 was in column 1
(everything is fine up to this point). Instead entering values for column 2,
3 and 4, I went back to my row 1 to edit the data. I then came back to my
second row and enter values for my columns 2, 3 and 4. I noticed that the
value of row 2 is now 2 not 1 and it seems like the number keeps on
incrementing.

Can we make the number increment only when an actual new row is created ? I
have included the code for column 1, all others are pretty much the same.

Dim mInputTable As New DataTable

Dim IDColStyle As New DataGridTextBoxColumn

Dim mIDCol As New DataColumn

'Initialize node column

mIDCol.ColumnName = "Node ID"

mIDCol.Caption = "Node ID"

mIDCol.AutoIncrement = True

mIDCol.AutoIncrementSeed = 0

mIDCol.AutoIncrementStep = 1

mIDCol.DataType = GetType(Integer)

IDColStyle.MappingName = "Node ID"

IDColStyle.NullText = ""

IDColStyle.Width = 72

IDColStyle.ReadOnly = True

IDColStyle.HeaderText = mIDCol.Caption

TableStyle.GridColumnStyles.Add(IDColStyle)

dgdInput.TableStyles.Add(TableStyle)

dgdInput.DataSource = mInputTable


Nov 21 '05 #1
1 1616
Sam,

I dont know why it happens in this case, however in my opinion is what is
the value of an autoincrement number is not important at all.

The value will be setted to a new number at update time, where when other
users has changed as well some row the start point will than be the actual
seed point of the database.

It is good to set the seed, the increment of that and the steps by the way.
And than use -1 for all.

http://msdn.microsoft.com/library/de...ementTopic.asp

I hope this helps something?

Cor
"Sam" <qd*@datawave.ca>
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. The
problem that I am having is that when I click on a cell of a new row but
decide not to enter a value and go back to any of the previous rows for
editting or whatever reason, the value of the new row will be incremented
by value of the AutoIncrementStep

Here is the problem I have

When I loaded the table for a first time, the first row has a value of 0
in column 1. I then entered 5, 5, 5 in column 2, 3, and 4 respectively. I
clicked on the 2nd row (new row), a new value of 1 was in column 1
(everything is fine up to this point). Instead entering values for column
2, 3 and 4, I went back to my row 1 to edit the data. I then came back to
my second row and enter values for my columns 2, 3 and 4. I noticed that
the value of row 2 is now 2 not 1 and it seems like the number keeps on
incrementing.

Can we make the number increment only when an actual new row is created ?
I have included the code for column 1, all others are pretty much the
same.

Dim mInputTable As New DataTable

Dim IDColStyle As New DataGridTextBoxColumn

Dim mIDCol As New DataColumn

'Initialize node column

mIDCol.ColumnName = "Node ID"

mIDCol.Caption = "Node ID"

mIDCol.AutoIncrement = True

mIDCol.AutoIncrementSeed = 0

mIDCol.AutoIncrementStep = 1

mIDCol.DataType = GetType(Integer)

IDColStyle.MappingName = "Node ID"

IDColStyle.NullText = ""

IDColStyle.Width = 72

IDColStyle.ReadOnly = True

IDColStyle.HeaderText = mIDCol.Caption

TableStyle.GridColumnStyles.Add(IDColStyle)

dgdInput.TableStyles.Add(TableStyle)

dgdInput.DataSource = mInputTable

Nov 21 '05 #2

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

Similar topics

1
by: Chris | last post by:
I'm having trouble Serializing a System.Data.DataColumn object. When I try to serialize it, I get the following: System.NotSupportedException: Cannot serialize member...
0
by: Neil | last post by:
Hi, I'm getting some strange results using the autoincrement column on my datatable. I'm populating a datatable with data from my database and displaying this in a datagrid. The first time I get...
5
by: Larry Bird | last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module...
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 to the ContactId column. I am experiencing a...
5
by: JC Voon | last post by:
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...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
by: SWIL | last post by:
Hi, I made my own datacolumn Class which inherits from Data.DataColumn. To this class I have added 2 properties. To add datacolumn created through my new class I have to call.. ...
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 autoincrement is used in various locations in 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 execute it. Then I remove PK, it works all fine...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.