Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created an application using EMPID and Ename how the Emp id can be generated auto matically that means it should automatically display the emp id to the textbox.
Posted

I'm assuming that you are using SQL DB..

C#
// Define one method
public int CountEmpID()
{
    string SelStr = "select EMPID from Employee";
    SqlDataAdapter da = new SqlDataAdapter(SelStr, con);
    DataTable dt = new DataTable();
    
    da.Fill(dt);
    
    return dt.Rows.Count;
}

//Page_Load event :
int e_id = CountEmpID();
EmpIDTxt.Text = e_id.ToString();
 
Share this answer
 
For generating ID field auto matically, make it identity field, Remember, its datatype must be int.

Thanks
 
Share this answer
 
Assuming that Empid is generated by a database as an identity value, then you cannot display it until you have inserted the record - it is only defined at that point. Think about it: if you have two users running the same software, they can't both have the same EmpId ready for the next input!

If that isn't what you are trying to do, then please explain in better detail, remember that we can't see your screen, access your HDD, or read your mind. :laugh:
 
Share this answer
 
Comments
Dhritirao's 20-Dec-12 3:11am    
actually i have two tables and empid is common column in two tables
OriginalGriff 20-Dec-12 3:47am    
Then you need to explain in more detail exactly what you need help with!
Lets assume you are entering a new employee's details and you already have generated an ID based on the number of records in your table. Suddenly there is the Pizza delivery on your doorstep and you go to answer that. You come back after 2 minutes and press save button. But in the meanwhile another user has entered an employee's details and he too got the same ID as the number of rows in your table didn't change because you were busy with the Pizza boy. Aren't you violating the primary key constraint(considering no two employees can have same ID)?
 
Share this answer
 

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