PC Review


Reply
Thread Tools Rate Thread

AutoIncrementSeed not working right HELP!!

 
 
Joe
Guest
Posts: n/a
 
      20th Feb 2005
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.


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      20th Feb 2005
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


 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      20th Feb 2005
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" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      20th Feb 2005
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 [MVP C#]" <miha at rthand com> wrote in message
news:#(E-Mail Removed)...
> 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" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
> news:(E-Mail Removed)...
> > 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.
> >
> >

>
>



 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      20th Feb 2005
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" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
news:%23gKoE%(E-Mail Removed)...
> 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 [MVP C#]" <miha at rthand com> wrote in message
> news:#(E-Mail Removed)...
>> 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" <J_no_spam@_no_spam_Fishinbrain.com> wrote in message
>> news:(E-Mail Removed)...
>> > 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.
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoIncrementSeed CHANGES after DataSet.Fill Trygve Lorentzen Microsoft ADO .NET 6 1st Dec 2006 03:48 PM
Bug with DataColumn.AutoIncrementSeed =?Utf-8?B?QXhlbEhlY2tlcg==?= Microsoft ADO .NET 1 1st Sep 2006 12:50 PM
AutoIncrementSeed une solution complète qui marche Jean-Luc PUCHOT Microsoft ADO .NET 1 8th Mar 2005 07:52 PM
AutoIncrementSeed still a problem Gerry Viator Microsoft ADO .NET 2 14th Oct 2004 08:19 PM
AutoincrementSeed and Datagrid =?Utf-8?B?bXJlbmFsZG8=?= Microsoft Dot NET Framework Forms 0 17th Mar 2004 08:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:52 AM.