469,277 Members | 2,117 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,277 developers. It's quick & easy.

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 1224
=?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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
3 posts views Thread by Jack | last post: by
3 posts views Thread by googleboy | last post: by
37 posts views Thread by Hilton | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.