how to create autogenerateid in asp.net

Posted by Ramakrishna188 under C# on 6/21/2012 | Points: 10 | Views : 699 | Status : [Member] | Replies : 2
i have one table operationsdeatil . i will enter all details like patientname, patientid but i want create the operationid automaticall like ope_1,ope_2,,,etc.
thankyou




Responses

Posted by: Ajay.Kalol on: 6/21/2012 [Member] Starter | Points: 25

Up
0
Down
if you want to generate ID like ope_1,...
then you have to check DB every time you enter Data for getting Latest ID and then Increment no and also check for already exist..

another way for unique ID : System.Guid.NewGuid().ToString()
From Sql Server : Select NEWID()

Ajay
ajaypatelfromsanthal.blogspot.in

Ramakrishna188, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sekar.C on: 6/21/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Check this code
void autoid()

{
//Get max of id from table then assign to tableid
string tableid = "Opt_10";
string[] splitid = tableid.Split('_');
int incid = Convert.ToInt16(splitid[1]);
incid++;
string newid = "Po_" + incid++;
//you call this method to needed place
}


Regards
Sekar.c

Ramakrishna188, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response