473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

VB.NET: How to Enter Values in AutoIncrement Columns of DataTable.

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.
Sep 12 '07 #1
2 5790
Try declaring the DS as Global(to use it only once). I think that should work.

Thanks
Sep 13 '07 #2
Hi Thanks for the reply.

I figured it out. What I did was every time inserting a row before reading XML file I would create the schema for my DS. And it did the trick. Anyways, Thanks very much for the reply.
Sep 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Frnak McKenney | last post by:
One part of a customer project I'm working on involves what seem like fairly straightforward updates to a set of related tables. While I've developed software for a number of years (it only seems...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
5
by: JC Voon | last post by:
Hi: How to reset the autoincrement value generated by DataTable ? I've master and detail table, the detail table has a autoincrement column, each time i add a new master record, i need to...
1
rizwan6feb
by: rizwan6feb | last post by:
I have a DataTable with thousands of records, i want to show these records on per page basis ( i.e a DataGridView showing first 20 records and next button to show next 20 records ...) To achieve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.