Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

autoincrement column not persisting when writing dataset to disk

Posted on 2010-11-08
6
Medium Priority
?
343 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
5 Comments
 
LVL 7

Accepted Solution

by:
whityum earned 2000 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

783 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