Solved

autoincrement column not persisting when writing dataset to disk

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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