AutoIncrementSeed not working right HELP!!

  • Thread starter Thread starter Joe
  • Start date Start date
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.
 
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
 
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?
 
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.
 
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.
 
Back
Top