Hello,
I am trying to create a Dataset and save it to an XML file. I have one column “JobID” for which I have set the autoincrement property to true. Here is the function that creates and save the dataset:
Public Sub CreateDataSet()
Dim tbMain As DataTable = New DataTable("UploadLog")
'Job ID – Auto increments
Dim drJobID As New DataColumn("JobID")
drJobID.DataType = Type.GetType("System.Int64")
drJobID.Unique = True
drJobID.AllowDBNull = False
drJobID.ReadOnly = True
drJobID.AutoIncrement = True
drJobID.AutoIncrementSeed = 1000
drJobID.AutoIncrementStep = 1
tbMain.Columns.Add(drJobID)
'Upload Type
Dim drUploadType As New DataColumn("UploadType")
drUploadType.DataType = Type.GetType("System.String")
drUploadType.AllowDBNull = False
tbMain.Columns.Add(drUploadType)
'Status
Dim drStatus As New DataColumn("Status")
drStatus.DataType = Type.GetType("System.String")
tbMain.Columns.Add(drStatus)
Dim ds As New DataSet
ds = New DataSet("MediaTraqLogs")
ds.Tables.Add(tbMain)
ds.WriteXmlSchema(sFileName)
End Sub
Now if I try to add new row in this data table the auto increment column does not auto-increments. Here is how I am adding row into this datatable:
Public Sub AddDataRow(ByVal Status As String, ByVal UploadType As String)
Dim DS As New DataSet()
DS.ReadXml(sFileName)
Dim tbUpload As DataTable = DS.Tables("UploadLog")
Dim oRow As DataRow = tbUpload.NewRow
oRow.Item("Status") = Status
oRow.Item("UploadType") = UploadType
tbUpload.Rows.Add(oRow)
DS.AcceptChanges()
DS.WriteXml(sFileName)
End Sub
But for some reasons it give first row as Job ID = 1000 and does not give any JobID to next rows which I add to this table.
Please help, I don’t understand what I am doing wrong in here.