Solved

autoincrement column not persisting when writing dataset to disk

Posted on 2010-11-08
6
335 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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