473,791 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

35 New Member
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("Uplo adLog")

'Job ID – Auto increments
Dim drJobID As New DataColumn("Job ID")
drJobID.DataTyp e = Type.GetType("S ystem.Int64")
drJobID.Unique = True
drJobID.AllowDB Null = False
drJobID.ReadOnl y = True
drJobID.AutoInc rement = True
drJobID.AutoInc rementSeed = 1000
drJobID.AutoInc rementStep = 1
tbMain.Columns. Add(drJobID)


'Upload Type
Dim drUploadType As New DataColumn("Upl oadType")
drUploadType.Da taType = Type.GetType("S ystem.String")
drUploadType.Al lowDBNull = False
tbMain.Columns. Add(drUploadTyp e)

'Status
Dim drStatus As New DataColumn("Sta tus")
drStatus.DataTy pe = Type.GetType("S ystem.String")
tbMain.Columns. Add(drStatus)


Dim ds As New DataSet
ds = New DataSet("MediaT raqLogs")
ds.Tables.Add(t bMain)

ds.WriteXmlSche ma(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(ByVa l Status As String, ByVal UploadType As String)

Dim DS As New DataSet()

DS.ReadXml(sFil eName)

Dim tbUpload As DataTable = DS.Tables("Uplo adLog")

Dim oRow As DataRow = tbUpload.NewRow

oRow.Item("Stat us") = Status
oRow.Item("Uplo adType") = UploadType

tbUpload.Rows.A dd(oRow)

DS.AcceptChange s()

DS.WriteXml(sFi leName)

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 5872
santuvssantu
12 New Member
Try declaring the DS as Global(to use it only once). I think that should work.

Thanks
Sep 13 '07 #2
PulkitZery
35 New Member
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
1643
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 like centuries on days like this <grin>), I'm new to C# and ADO.NET and I'm running into problems with record deletions. I (think I am) applying ForeignKeyConstraints correctly. I'm not applying DataRelations (yet), but those _appear_ to be...
0
3169
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 datacolumns do not trigger their expression when other columns from which the expressions are derived are updated. Below is a basic example of what I am doing. User enters values into an asp.net form and clicks a button. Retrieve dataset from...
5
8098
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 reset the detail table autoincrement column to start from 1. I set the dataColumn AutoIncrementSeed=0 and AutoIncrementStep=1 each time i append a new master row, but it seem not work, it still remain
1
3772
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 this, i have added an Autoincrement Column to the DataTable so that i can use a filter on the Autoincrement Column to get the desired 20 records from the DataTable. I have used the following code Dim dc As New...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9023
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.