Solved

autoincrement column not persisting when writing dataset to disk

Posted on 2010-11-08
6
326 Views
Last Modified: 2012-05-10
I have an autoincrement column declared in a table that I'm using to persist data to disk. It's defined as follows
 Col14.ColumnName = "ID"
        Col14.DataType = GetType(Int32)
        Col14.AutoIncrement = True
        Col14.AutoIncrementSeed = 1
        Col14.AllowDBNull = False
        Col14.ReadOnly = True
        tblTransactionLog.Columns.Add(Col14)

As long as the table is retained in memory the "ID" column is incremented correctly. On application exit I save the dataset to disk using the following code.

ds.WriteXmlSchema(Me.TransactionFileName)
ds.WriteXml(Me.TransactionFileName).

When I launch the application again I read the dataset using the following code
 glbTransactionDS = New DataSet
 glbTransactionDS.ReadXml(Me.TransactionFileName)
 glbTransactionDS.ReadXmlSchema(Me.TransactionFileName)

When I add addtional rows to the datatable contained within the dataset all columns are added correctly with the exception of the ID column. See below
<?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <tblTransactionLog>
  <TransactionCode>R</TransactionCode>
  <ItemID>5804</ItemID>
  <Units>1</Units>
  <Location>DOCK</Location>
  <UserID>72</UserID>
  <TechScheduleID>0</TechScheduleID>
  <CustomerID>0</CustomerID>
  <ReasonCode>-2</ReasonCode>
  <Reference />
  <Remark />
  <WarehouseID>1</WarehouseID>
  <Serial />
  <ReturnError />
  <ID>1</ID>
  </tblTransactionLog>
- <tblTransactionLog>
  <TransactionCode>R</TransactionCode>
  <ItemID>5804</ItemID>
  <Units>2</Units>
  <Location>DOCK</Location>
  <UserID>72</UserID>
  <TechScheduleID>0</TechScheduleID>
  <CustomerID>0</CustomerID>
  <ReasonCode>-2</ReasonCode>
  <Reference />
  <Remark />
  <WarehouseID>1</WarehouseID>
  <Serial />
  <ReturnError />
  </tblTransactionLog>
  </NewDataSet>

How do I get the autoincrement column ID to persist when writing xml to disk?
0
Comment
Question by:bensonwalker
  • 2
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
whityum earned 500 total points
ID: 34084546
Loop through the XML and reset this:
Col14.AutoIncrementSeed = 1
to 1 greater than the max value of the ID field in the XML
0
 
LVL 1

Author Comment

by:bensonwalker
ID: 34085226
I was able to use a guid field in the table that was persisted on saves. Thank you for the response
0
 
LVL 7

Expert Comment

by:whityum
ID: 34085452
I answered the question as it was stated.
0
 
LVL 1

Author Comment

by:bensonwalker
ID: 34087471
Yes you did I apologize
0
 

Expert Comment

by:ModernMatt
ID: 34126735
I am starting the close process per the author's indication in http:#a34087471 that the answer has been provided.

ModernMatt
Experts Exchange Moderator
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now