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

About Code-generated primary key

I want to generate a primary key in ASP.Net through VB.Net code.Can someone
give some tips and ideas how to do that.What i am thinking is to:

1.Create an array of values(characters) from 0 to 9 and 'A' to 'Z'.
2.Then use a nested For loop to create various combinations.
3.Then checking whether these combinations exist in the field of the table
or not.

Can someone suggest a better way of doing that.Is it a good idea to create a
primary key in runtime as above stated.
What if i have to create a primary key for user ids for users from all over
the world(probably too huge or unlimited)?
Nov 19 '05 #1
4 1344
=?Utf-8?B?TWF4b29k?= <Ma****@discussions.microsoft.com> wrote in
news:F4**********************************@microsof t.com:
Can someone suggest a better way of doing that.Is it a good idea to
create a primary key in runtime as above stated.
What if i have to create a primary key for user ids for users from all
over the world(probably too huge or unlimited)?


Why don't you use a database AutoNumber or Identity field.

Or... take a look at System.GUID : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
Nov 19 '05 #2
The only way I've ever done this is via the Guid.NewGuid static member...

dim id as Guid = Guid.NewGuid
id.ToString()
http://en.wikipedia.org/wiki/GUID

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Maxood" <Ma****@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
I want to generate a primary key in ASP.Net through VB.Net code.Can someone
give some tips and ideas how to do that.What i am thinking is to:

1.Create an array of values(characters) from 0 to 9 and 'A' to 'Z'.
2.Then use a nested For loop to create various combinations.
3.Then checking whether these combinations exist in the field of the table
or not.

Can someone suggest a better way of doing that.Is it a good idea to create
a
primary key in runtime as above stated.
What if i have to create a primary key for user ids for users from all
over
the world(probably too huge or unlimited)?

Nov 19 '05 #3
Can you tell me how to read the MAC address of a workstation in VB.Net.Lets
say that i wan to generate a primary key based on MAC addresses.

"Karl Seguin" wrote:
The only way I've ever done this is via the Guid.NewGuid static member...

dim id as Guid = Guid.NewGuid
id.ToString()
http://en.wikipedia.org/wiki/GUID

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Maxood" <Ma****@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
I want to generate a primary key in ASP.Net through VB.Net code.Can someone
give some tips and ideas how to do that.What i am thinking is to:

1.Create an array of values(characters) from 0 to 9 and 'A' to 'Z'.
2.Then use a nested For loop to create various combinations.
3.Then checking whether these combinations exist in the field of the table
or not.

Can someone suggest a better way of doing that.Is it a good idea to create
a
primary key in runtime as above stated.
What if i have to create a primary key for user ids for users from all
over
the world(probably too huge or unlimited)?


Nov 19 '05 #4
Imports System.Management

Public Function GetFirstMac() As String
' returns the mac address without :'s for first network adapter found
' returns "" if none found

Const sQuery = "SELECT MacAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = true"
Dim oRet As ManagementObjectSearcher = New ManagementObjectSearcher(sQuery)
Dim MCol As ManagementObjectCollection = oRet.Get()
Dim MObj As ManagementObject
Dim MacNow As String
For Each MObj In MCol
Debug.WriteLine(MObj("MacAddress"))
MacNow = MObj("MacAddress")
If (Not IsNothing(MacNow)) Then
MacNow = Replace(MacNow, ":", "")
If Len(MacNow) = 6 * 2 Then ' 6 x hex
Return MacNow
End If
End If
Next
Return ""
End Function

There's another version at : http://www.dotnet247.com/247reference/msgs/4/21219.aspx

If you want to know how to do it in a PocketPC, see :
http://www.developmentnow.com/g/18_2...pplication.htm

Google is your friend.



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en EspaƱol : http://asp.net.do/foros/
======================================
"Maxood" <Ma****@discussions.microsoft.com> wrote in message news:B2**********************************@microsof t.com...
Can you tell me how to read the MAC address of a workstation in VB.Net.Lets
say that i wan to generate a primary key based on MAC addresses.

"Karl Seguin" wrote:
The only way I've ever done this is via the Guid.NewGuid static member...

dim id as Guid = Guid.NewGuid
id.ToString()
http://en.wikipedia.org/wiki/GUID

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Maxood" <Ma****@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com...
>I want to generate a primary key in ASP.Net through VB.Net code.Can someone
> give some tips and ideas how to do that.What i am thinking is to:
>
> 1.Create an array of values(characters) from 0 to 9 and 'A' to 'Z'.
> 2.Then use a nested For loop to create various combinations.
> 3.Then checking whether these combinations exist in the field of the table
> or not.
>
> Can someone suggest a better way of doing that.Is it a good idea to create
> a
> primary key in runtime as above stated.
> What if i have to create a primary key for user ids for users from all
> over
> the world(probably too huge or unlimited)?



Nov 19 '05 #5

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
77
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a...
35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
17
by: Rich S. | last post by:
Hello Just like everyone else, I am excited about how easily one can create Windows applications with the .NET platform, but for shareware, I have some serious reservations 1. Your code can be...
3
by: Jack | last post by:
On the 1st of January 1998, Bjarne Stroustrup gave an interview to the IEEE's 'Computer' magazine. Naturally, the editors thought he would be giving a retrospective view of seven years of...
3
by: googleboy | last post by:
Hi there. I have defined a class called Item with several (about 30 I think) different attributes (is that the right word in this context?). An abbreviated example of the code for this is: ...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
7
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my...
37
by: Hilton | last post by:
Hi, for (int i = 0; i < list.Count; i++) has a hidden performance hit; i.e. list.Count gets evaluated each time, so we write something like: int listCount = list.Count; for (int i = 0; i <...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.