Solved

autoincrement column not persisting when writing dataset to disk

Posted on 2010-11-08
6
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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