AutoIncrement Columns

G

Guest

Hi,

I'm wondering if it's possible to regenerate the increment id's in an
AutoIncrement Column?

My situation is this...I have a client application that is recieving a
several DataTables from a service. The DataTables contain an auto increment
column which is guaranteed to be unique within that table but I need to merge
the tables together to create a new table and still have a unique column.

Orignally I was taking the first table as a base and then adding new rows to
this for the other tables using LoadDataRow since the structure will always
be the same.

Since the format of each table is the same I'm using
LoadDataRow(myRowToAdd). I have tried creating a new AutoIncrementColumn and
LoadingDataRow but this doesn't work, I end up with NULLS in the new Column
and of course non unique values in the existing.

So I guess my question is what is the best way to create this new
autoincrement column? I'm hoping I don't have to loop through the datatables
that come in because I will be recieving updates to all this data and think
this could be quite slow.

Any help appreciated.

Thanks
 
C

Cor Ligthert [MVP]

Neil,

Therefore try to forget in this century the simple autoincrement id and use
the Global Unique Identifier (GUID) in SQL the Unique Identifier to make
ID's. You know, you are not the first with the problems you are describing.

Just my thought,

Cor
 
G

Guest

Hi Cor,

Thanks for the suggestion. I have used the GUID before but in this case it
won't help me. I should have mentioned why I was wanting the AutoIncrement
Column...

I have an initial dataload stage which see's my client recieve several data
tables, each of these is combined into one table and then bound to a grid. I
also will recieve updates to the initial data loads and new datarows as time
goes on. I was using the AutoIncrement column as a Row Indexer something
along the lines of code below (excuse syntax errors). This just saves me
looping through the initial data table for each update I have and hence it's
a bit quicker. Otherwise I might be looping through my initial data table
(2000 records) just to update 2 rows. Perhaps there is a better way to do
this...?

Thanks


string uniqueIdent = myUpdateRow["UniqueKey"].ToString();

DataRow foundRow = myInitialData.Find(uniqueIdent);

if(foundRow != null) //it's an update
{
int rowIdx = (int)foundRow["myAutoIncrementCol"].ToString();

//Loop through all columns in the row to see if any values have changed
using RowIdx
myInitialData.Rows[rowIdx][colIdx] != updateRow[colIdx]
}
else //New Record
{
myInitialData.LoadDataRow(updateRow);
}
 
C

Cor Ligthert [MVP]

Neil,

Are you sure that you cannot use the merge.

http://www.vb-tips.com/dbpages.aspx?ID=edb1409d-5394-468f-a63f-de3a5d92b14a

Cor


Neil said:
Hi Cor,

Thanks for the suggestion. I have used the GUID before but in this case it
won't help me. I should have mentioned why I was wanting the AutoIncrement
Column...

I have an initial dataload stage which see's my client recieve several
data
tables, each of these is combined into one table and then bound to a grid.
I
also will recieve updates to the initial data loads and new datarows as
time
goes on. I was using the AutoIncrement column as a Row Indexer something
along the lines of code below (excuse syntax errors). This just saves me
looping through the initial data table for each update I have and hence
it's
a bit quicker. Otherwise I might be looping through my initial data table
(2000 records) just to update 2 rows. Perhaps there is a better way to do
this...?

Thanks


string uniqueIdent = myUpdateRow["UniqueKey"].ToString();

DataRow foundRow = myInitialData.Find(uniqueIdent);

if(foundRow != null) //it's an update
{
int rowIdx = (int)foundRow["myAutoIncrementCol"].ToString();

//Loop through all columns in the row to see if any values have changed
using RowIdx
myInitialData.Rows[rowIdx][colIdx] != updateRow[colIdx]
}
else //New Record
{
myInitialData.LoadDataRow(updateRow);
}



Cor Ligthert said:
Neil,

Therefore try to forget in this century the simple autoincrement id and
use
the Global Unique Identifier (GUID) in SQL the Unique Identifier to make
ID's. You know, you are not the first with the problems you are
describing.

Just my thought,

Cor
 
A

AMDRIT

If the merge function does not work, you can overrload it to do what you
want it to do. Set your step and increment to -1, this way you will not run
into duplicate numbers.


Cor Ligthert said:
Neil,

Are you sure that you cannot use the merge.

http://www.vb-tips.com/dbpages.aspx?ID=edb1409d-5394-468f-a63f-de3a5d92b14a

Cor


Neil said:
Hi Cor,

Thanks for the suggestion. I have used the GUID before but in this case
it
won't help me. I should have mentioned why I was wanting the
AutoIncrement
Column...

I have an initial dataload stage which see's my client recieve several
data
tables, each of these is combined into one table and then bound to a
grid. I
also will recieve updates to the initial data loads and new datarows as
time
goes on. I was using the AutoIncrement column as a Row Indexer something
along the lines of code below (excuse syntax errors). This just saves me
looping through the initial data table for each update I have and hence
it's
a bit quicker. Otherwise I might be looping through my initial data table
(2000 records) just to update 2 rows. Perhaps there is a better way to do
this...?

Thanks


string uniqueIdent = myUpdateRow["UniqueKey"].ToString();

DataRow foundRow = myInitialData.Find(uniqueIdent);

if(foundRow != null) //it's an update
{
int rowIdx = (int)foundRow["myAutoIncrementCol"].ToString();

//Loop through all columns in the row to see if any values have changed
using RowIdx
myInitialData.Rows[rowIdx][colIdx] != updateRow[colIdx]
}
else //New Record
{
myInitialData.LoadDataRow(updateRow);
}



Cor Ligthert said:
Neil,

Therefore try to forget in this century the simple autoincrement id and
use
the Global Unique Identifier (GUID) in SQL the Unique Identifier to make
ID's. You know, you are not the first with the problems you are
describing.

Just my thought,

Cor

"Neil" <[email protected]> schreef in bericht
Hi,

I'm wondering if it's possible to regenerate the increment id's in an
AutoIncrement Column?

My situation is this...I have a client application that is recieving a
several DataTables from a service. The DataTables contain an auto
increment
column which is guaranteed to be unique within that table but I need
to
merge
the tables together to create a new table and still have a unique
column.

Orignally I was taking the first table as a base and then adding new
rows
to
this for the other tables using LoadDataRow since the structure will
always
be the same.

Since the format of each table is the same I'm using
LoadDataRow(myRowToAdd). I have tried creating a new
AutoIncrementColumn
and
LoadingDataRow but this doesn't work, I end up with NULLS in the new
Column
and of course non unique values in the existing.

So I guess my question is what is the best way to create this new
autoincrement column? I'm hoping I don't have to loop through the
datatables
that come in because I will be recieving updates to all this data and
think
this could be quite slow.

Any help appreciated.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top