About Code-generated primary key

G

Guest

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)?
 
L

Lucas Tam

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 : )
 
G

Guest

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.
 
J

Juan T. Llibre

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_...Address-using-PocketPC-VB-NET-application.htm

Google is your friend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top