Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I design regesitration form in that i have one textbox=ID, when i regester i want to get ID number automatically, if any one know plz send the code............
Posted

There are many way generate auto ID. U can Use according to ur need:

But here u have not clear ur requirement so i m giving answer in general.

1. Use Auto Increment field : http://www.w3schools.com/sql/sql_autoincrement.asp[^]

2.use GUID : http://msdn.microsoft.com/en-us/library/system.guid.newguid.aspx[^]

3.Use c# to generate next number :
If u r using simple number as ID than do following to get new ID on page load
i. get max value from ID column using max()
ii. increment it by 1
iii. use new value in textbox

4.use custom ID :

U can have ur format of ID like M001, PR003, MAB1 etc

So for this kind of id u can do following
i. get max value from ID column using max()
ii. separate number and char
iii. do increment in number
iv. join number and character
v. use new value in textbox

U can have more methods. search Google for that
 
Share this answer
 
Comments
rockpune 22-Feb-12 2:49am    
4.use custom ID :

U can have ur format of ID like M001, PR003, MAB1 etc

So for this kind of id u can do following
i. get max value from ID column using max()
ii. separate number and char
iii. do increment in number
iv. join number and character
v. use new value in textbox



i want like above plz give me above example code
CRDave1988 22-Feb-12 2:54am    
What u have try? where u r facing problem?
rockpune 22-Feb-12 2:58am    
when i add new item i want to get ID number automatically for each add new item....nothing but token number
CRDave1988 22-Feb-12 3:01am    
ya man I get what u want but I am asking that what u have code so far for that? or u r just expecting a ready-made solution from us.
rockpune 22-Feb-12 3:03am    
private void Addnew()
{
//For getting the LocationID

string test = string.Empty;
DataSet d = PDataset("SELECT TOP (1) ObjID, ObjName, ObjParentID FROM tblObjectives order by ObjID Desc");
string a = "";
try
{
this code is if your id has only degit

C#
string maxid = "";
string sql = "Select Top(1) ID_Receipt from Receipt ORDER BY ID_Receipt DESC";
            SqlCommand testcommand = new SqlCommand(sql, conn);
            rdr = testcommand.ExecuteReader();
            while (rdr.Read())
            {
              maxid = rdr["ID_Receipt"].ToString();
            }
            int nummaxid = Convert.toInt32(maxid);
            nummaxid++;
            textbox1.Text = nummaxid.toString();


if your id have string you maybe use function split

Good luck. Pls Mark if answer
 
Share this answer
 
v3
Comments
CRDave1988 22-Feb-12 3:04am    
good
pongpanut 22-Feb-12 4:18am    
thank you CRDave1988

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900