Link to home
Start Free TrialLog in
Avatar of jettman26
jettman26

asked on

Need direction on inserting a unique value for new record in MSSQL database

I have a page called Main_info.aspx that has a DropDownList box that pulls the class_name from CLASSES table.  It also has a Calendar control and a text box.  All of these values are written to the INFO table.  With each record in the INFO table needs to be a unique id, info_id is the Primary Key and this needs to be a unique id.  
How do I make it so each New record inserted into the INFO table will have a unique ID?  
It can start at 1 and go to infinity, it really doesn't matter to me.
Also, what does the Data Type need to be in the database for this unique id, i.e. info_id?
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jettman26
jettman26

ASKER

I am using MS SQL for a database.
Would this be 'uniqueidentifier' for the DataType in MS SQL?
Keep DataType to int

& if you're using Enterprise Manager to manage your Data, when you click on your Field Name you'll see Columns on the bottom, select like following:

Identity: Yes
Identity Seed: 1
Identity Increment: 1

-tushar
Got it.

Since I added this info_id field, does it make the following statement not work anymore since the order of my columns in my Info table is:
info_id
class_name
info_date
notes

myCommand.CommandText = "INSERT INTO INFO VALUES ('" & classDownList.SelectedValue & "', '" & calendar.SelectedDate & "', '" & notesText.Text & "')"
You'll need to modify it like following:

"INSERT INTO INFO(class_name, info_date, notes) VALUES ('" & classDownList.SelectedValue & "', '" & calendar.SelectedDate & "', '" & notesText.Text & "')"

-tushar
Works great!
Now I have one more question for now that I am posting if you want it?
I'll pass it now... will check it out tomorrow morning if it'll be open..