473,394 Members | 1,735 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,394 software developers and data experts.

unique ID's

is there an easy way to generate unique ID's for a DataSet Table or am I
just going to have to generate a random number and search the db to see if
it's been used already?
Nov 15 '05 #1
8 14923
Use the following statement to generate the Unique id

System.Guid.NewGuid()

Regards,
Amal
Nov 15 '05 #2
Chuck,

depending on how you are using the DataTable, you probably don't even need
to worry about it. If you are writing back to the DB, the DataAdapter will
take care of this issue through it's UpdateCommand.

However, if you need to generate the unique number in the code, here is the
process for setting up a new DataTable that automaticaly increments an ID
column.

If you bind the resultant DataTable to a DataGrid you will see it creating
the ID value as you enter new records.

-------------------------
System.Data.DataTable dt = new DataTable("MyDataTable");

System.Data.DataColumn dc = new DataColumn("TableID");
dc.AutoIncrement = true;
dc.AutoIncrementSeed=1;
dc.AutoIncrementStep=1;
dt.Columns.Add(dc);

dc = new DataColumn("ValueField");
dt.Columns.Add(dc);
--------------------------

Kirk Graves
KRGIT Software

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:OR*************@tk2msftngp13.phx.gbl...
is there an easy way to generate unique ID's for a DataSet Table or am I
just going to have to generate a random number and search the db to see if
it's been used already?

Nov 15 '05 #3
Use the following statement to generate the Unique id

System.Guid.NewGuid()

Regards,
Amal
Nov 15 '05 #4
Chuck,

depending on how you are using the DataTable, you probably don't even need
to worry about it. If you are writing back to the DB, the DataAdapter will
take care of this issue through it's UpdateCommand.

However, if you need to generate the unique number in the code, here is the
process for setting up a new DataTable that automaticaly increments an ID
column.

If you bind the resultant DataTable to a DataGrid you will see it creating
the ID value as you enter new records.

-------------------------
System.Data.DataTable dt = new DataTable("MyDataTable");

System.Data.DataColumn dc = new DataColumn("TableID");
dc.AutoIncrement = true;
dc.AutoIncrementSeed=1;
dc.AutoIncrementStep=1;
dt.Columns.Add(dc);

dc = new DataColumn("ValueField");
dt.Columns.Add(dc);
--------------------------

Kirk Graves
KRGIT Software

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:OR*************@tk2msftngp13.phx.gbl...
is there an easy way to generate unique ID's for a DataSet Table or am I
just going to have to generate a random number and search the db to see if
it's been used already?

Nov 15 '05 #5
exactly what i needed. thank you Kirk.

"Kirk Graves" <kr***********@yahoo.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
Chuck,

depending on how you are using the DataTable, you probably don't even need
to worry about it. If you are writing back to the DB, the DataAdapter will take care of this issue through it's UpdateCommand.

However, if you need to generate the unique number in the code, here is the process for setting up a new DataTable that automaticaly increments an ID
column.

If you bind the resultant DataTable to a DataGrid you will see it creating
the ID value as you enter new records.

-------------------------
System.Data.DataTable dt = new DataTable("MyDataTable");

System.Data.DataColumn dc = new DataColumn("TableID");
dc.AutoIncrement = true;
dc.AutoIncrementSeed=1;
dc.AutoIncrementStep=1;
dt.Columns.Add(dc);

dc = new DataColumn("ValueField");
dt.Columns.Add(dc);
--------------------------

Kirk Graves
KRGIT Software

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:OR*************@tk2msftngp13.phx.gbl...
is there an easy way to generate unique ID's for a DataSet Table or am I
just going to have to generate a random number and search the db to see if it's been used already?


Nov 15 '05 #6
exactly what i needed. thank you Kirk.

"Kirk Graves" <kr***********@yahoo.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
Chuck,

depending on how you are using the DataTable, you probably don't even need
to worry about it. If you are writing back to the DB, the DataAdapter will take care of this issue through it's UpdateCommand.

However, if you need to generate the unique number in the code, here is the process for setting up a new DataTable that automaticaly increments an ID
column.

If you bind the resultant DataTable to a DataGrid you will see it creating
the ID value as you enter new records.

-------------------------
System.Data.DataTable dt = new DataTable("MyDataTable");

System.Data.DataColumn dc = new DataColumn("TableID");
dc.AutoIncrement = true;
dc.AutoIncrementSeed=1;
dc.AutoIncrementStep=1;
dt.Columns.Add(dc);

dc = new DataColumn("ValueField");
dt.Columns.Add(dc);
--------------------------

Kirk Graves
KRGIT Software

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:OR*************@tk2msftngp13.phx.gbl...
is there an easy way to generate unique ID's for a DataSet Table or am I
just going to have to generate a random number and search the db to see if it's been used already?


Nov 15 '05 #7
thanks for the reply Amal.

"Amalorpavanathan Yagulasamy (AMAL)" <an*******@discussions.microsoft.com>
wrote in message news:A3**********************************@microsof t.com...
Use the following statement to generate the Unique id

System.Guid.NewGuid()

Regards,
Amal

Nov 15 '05 #8
thanks for the reply Amal.

"Amalorpavanathan Yagulasamy (AMAL)" <an*******@discussions.microsoft.com>
wrote in message news:A3**********************************@microsof t.com...
Use the following statement to generate the Unique id

System.Guid.NewGuid()

Regards,
Amal

Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: reneeccwest | last post by:
Hello, I plan to create a table with 3 unique keys. Combination of three fields has to be unique for each row in a table that are vendor ID (char 8), vendor name (char 40), and vendor...
9
by: Rolf Kemper | last post by:
Dear Experts, I got stuck with the following problem and need your help. What I wnat to do is to get a set of distinct nodes. Before the distinct I have selected the multiple occourences...
12
by: Russell E. Owen | last post by:
I have several situations in my code where I want a unique identifier for a method of some object (I think this is called a bound method). I want this id to be both unique to that method and also...
29
by: Lauren Wilson | last post by:
Does anyone know how the following info is extracted from the user's computer by a Front Page form? HTTP User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107...
3
by: Jozef | last post by:
Hello, Is there any way to acquire a unique Machine ID, Hard Drive ID or Windows Installation ID? Im looking for a way to uniquely identify a physical installation and connection. The problem...
10
by: Jerry LeVan | last post by:
Hi, I am futzing around with Andrew Stuarts "Catchmail" program that stores emails into a postgresql database. I want to avoid inserting the same email more than once... (pieces of the email...
9
by: dave m | last post by:
I need to be able to retrieve a unique ID from a users PC. I needs to be something a user could not easily change, like the computer name. Could someone point me in the right direction to find ...
2
by: Peter Oliphant | last post by:
Sometimes it's hard to get straight when passing or storing or returning an instance of a class whether you are still dealing with the original object or a copy. For example, the '=' operator used...
1
by: Danny Liberty | last post by:
I need some opionions on an issue here... Suppose I want to keep a collection of objects, each need to be uniquely identified by a number. This number has no meaning as long as it's unique, so it...
13
by: gamernaveen | last post by:
I am coding a script , where basically the user has to enter his name , choose file , file comments if required and upload. The file comments , name , filename will be stored in the database with...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.