Bug with DataColumn.AutoIncrementSeed

G

Guest

Hi! I think I found a bug with DataColumn.AutoIncrementSeed. I tried to
communicate it via the Microsoft Feedback center, but after about half an
hour of trying to get through the feedback process without webforms breaking
down, I gave up.

The bug is: Under certain circumstances, the number to be automatically
incremented has a false value.

This is how to reproduce the bug (complete code below):
1) Call TestCode1(): an XML file TEST.xml is created in C:\
2) Call TestCode2() with a breakpoint in line

dr["Text"] = "Text2";
(= third to last line)

3) The new line created should have an ID of 1 (ID of existing line, which
is 0, plus 1); but it has an ID of 0.

With an AutoIncrementSeed of 1 (instead of 0), the problem disappears (the
two IDs are correctly numbered 1 and 2).

--Complete code:

private void TestCode1()
{
System.Data.DataSet ds = new DataSet("TestDS");
System.Data.DataTable dt = new DataTable("Test");
ds.Tables.Add(dt);
System.Data.DataColumn dc1 = new DataColumn("ID", typeof(int));
dt.Columns.Add(dc1);
dt.Columns[0].AutoIncrement = true;
dt.Columns[0].AutoIncrementSeed = 1;
dt.Columns[0].AutoIncrementStep = 1;
System.Data.DataColumn dc2 = new DataColumn("Text",
typeof(string));
dt.Columns.Add(dc2);
System.Xml.XmlDataDocument xmlTest = new XmlDataDocument(ds);

System.Data.DataRow dr = dt.NewRow();
dr["Text"] = "Text1";
dt.Rows.Add(dr);
dt.AcceptChanges();

xmlTest.Save("C:\Test.xml");

dr = dt.NewRow();
dr["Text"] = "Text2";
dt.Rows.Add(dr);
dt.AcceptChanges();
}

private void TestCode2()
{
System.Data.DataSet ds = new DataSet("TestDS");
System.Data.DataTable dt = new DataTable("Test");
ds.Tables.Add(dt);
System.Data.DataColumn dc1 = new DataColumn("ID", typeof(int));
dt.Columns.Add(dc1);
dt.Columns[0].AutoIncrement = true;
dt.Columns[0].AutoIncrementSeed = 1;
dt.Columns[0].AutoIncrementStep = 1;
System.Data.DataColumn dc2 = new DataColumn("Text",
typeof(string));
dt.Columns.Add(dc2);
System.Xml.XmlDataDocument xmlTest = new XmlDataDocument(ds);

xmlTest.Load("C:\Test.xml");
ds.AcceptChanges();

System.Data.DataRow dr = dt.NewRow();
dr["Text"] = "Text2";
dt.Rows.Add(dr);
dt.AcceptChanges();
}


Axel Hecker
 
G

Guest

Correction of previous post:

The code represented sets AutoIncrementSeed=1

This is when the bug does *not* appear.

If you set AutoIncrementSeed=0 (in TestCode1() as well as in TestCode2()),
the problem will appear.

Sorry. Axel Hecker.
 

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