AutoIncrementSeed not working right HELP!!

J

Joe

Given the following code new rows should have their AutoIncrement column set
to -1, -2, -3, etc... but this isn't the case.

When I inspect the new row it shows the last positive value -1 for the new
row yet when I look at the column both Auto properties are set as below. I
double verified by looking at the row than col like this:
datatable.Rows[45]["idx"] and the column datatable.Columns["idx"]. This way
I know I'm looking at the right item.
In addition, when inspecting the newrow I see that rowID = -1, newRecord
= -1.


da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(dt);

foreach (DataColumn c in dt.Columns)
{
if (c.AutoIncrement == true)
{
c.AutoIncrementSeed = -1;
c.AutoIncrementStep = -1;
break;
}
}

I hope I'm just overlooking something.
 
C

Cor Ligthert

Joe,

Think on a multiuser environment.

When that new row is inserted in the database it will be changed.

However not in your dataset.

For that you have to clean the dataset and to fill the updated table
completly new again.

Not alone therefore it is in my opinon better to use a Guid as an
uniqueidentifier

I hope this helps?

Cor
 
M

Miha Markic [MVP C#]

Hi Joe,

Autoincrement applies only when you create new rows in memory (in
DataTable).
Where exactly are your news rows comming from?
How do you create them?
 
J

Joe

These records are only inserted by one person. It's an import program so
there can never be multiple users.

DataTable dt = new DataTable("MyTable");
da.Fill(dt);
// set the AutoIncrement properties for the column.
....
DataRow dr = dt.NewRow();
....
....
dt.Rows.Add(dr);

It seems the seed only applies if the DataTable is empty to begin with.

Miha Markic said:
Hi Joe,

Autoincrement applies only when you create new rows in memory (in
DataTable).
Where exactly are your news rows comming from?
How do you create them?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Joe said:
Given the following code new rows should have their AutoIncrement column
set
to -1, -2, -3, etc... but this isn't the case.

When I inspect the new row it shows the last positive value -1 for the new
row yet when I look at the column both Auto properties are set as below. I
double verified by looking at the row than col like this:
datatable.Rows[45]["idx"] and the column datatable.Columns["idx"]. This
way
I know I'm looking at the right item.
In addition, when inspecting the newrow I see that rowID = -1, newRecord
= -1.


da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(dt);

foreach (DataColumn c in dt.Columns)
{
if (c.AutoIncrement == true)
{
c.AutoIncrementSeed = -1;
c.AutoIncrementStep = -1;
break;
}
}

I hope I'm just overlooking something.
 
M

Miha Markic [MVP C#]

Hi Joe,

Assign AutoIncrementStep first and then AutoIncrementSeed.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Joe said:
These records are only inserted by one person. It's an import program so
there can never be multiple users.

DataTable dt = new DataTable("MyTable");
da.Fill(dt);
// set the AutoIncrement properties for the column.
...
DataRow dr = dt.NewRow();
...
...
dt.Rows.Add(dr);

It seems the seed only applies if the DataTable is empty to begin with.

Miha Markic said:
Hi Joe,

Autoincrement applies only when you create new rows in memory (in
DataTable).
Where exactly are your news rows comming from?
How do you create them?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Joe said:
Given the following code new rows should have their AutoIncrement
column
set
to -1, -2, -3, etc... but this isn't the case.

When I inspect the new row it shows the last positive value -1 for the new
row yet when I look at the column both Auto properties are set as
below. I
double verified by looking at the row than col like this:
datatable.Rows[45]["idx"] and the column datatable.Columns["idx"]. This
way
I know I'm looking at the right item.
In addition, when inspecting the newrow I see that rowID = -1,
newRecord
= -1.


da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(dt);

foreach (DataColumn c in dt.Columns)
{
if (c.AutoIncrement == true)
{
c.AutoIncrementSeed = -1;
c.AutoIncrementStep = -1;
break;
}
}

I hope I'm just overlooking something.
 

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