//this code in asp.cs file for autoid
private void Autoid()
{
string Mode = "M";
pr.Mode = Mode;
dt = new DataTable();
dt = logic.Maxid(pr);
if (dt.Rows[0][0].ToString() != "")
{
txtEMPId.Text = (int.Parse(dt.Rows[0][0].ToString()) + 1).ToString();
}
else
txtRMPId.Text = "1";
}
//inclass cs file
public DataTable InsertEmployeeFormat(ParametersBusinessObjects Schbo)
{
DataTable dt = new DataTable();
DataAcessHelper dashp = new DataAcessHelper();
if (Schbo.Mode != "M")
{
SqlCommand cmd = dashp.CreateCommand("sp_Employeedetails");
dashp.AddParameter(cmd, "@EmpIdid", SqlDbType.Int, ParameterDirection.Input, 4, Schbo.School);
dashp.AddParameter(cmd, "@EmpName", SqlDbType.VarChar, ParameterDirection.Input, 30, Schbo.SchoolName);
dashp.AddParameter(cmd, "@LandlineNo", SqlDbType.VarChar, ParameterDirection.Input, 20, Schbo.LandlineNo);
dashp.AddParameter(cmd, "@MobileNo", SqlDbType.VarChar, ParameterDirection.Input, 20, Schbo.MobileNo);
dashp.AddParameter(cmd, "@Address", SqlDbType.VarChar, ParameterDirection.Input, 30, Schbo.Address);
dashp.AddParameter(cmd,"@DateofBirth",SqlDbType.Date,ParameterDirection.Input ,30, Schbo.strDate);
dashp.AddParameter(cmd, "@EndDate", SqlDbType.Date, ParameterDirection.Input, 30, Schbo.EndDate);
dashp.AddParameter(cmd, "@Flag", SqlDbType.VarChar, ParameterDirection.Input, 2, Schbo.Mode);
if (Schbo.Mode != "A" && Schbo.Mode != "S" && Schbo.Mode != "G" && Schbo.Mode !="N")
{
dashp.ExecuteStoredProcedure(cmd);
}
else
{
dt = dashp.GetDataTable(cmd);
}
}
else
{
SqlCommand cmd = dashp.CreateCommand("sp_maxid");
dt = dashp.GetDataTable(cmd);
}
return dt;
}
//stored procedure
ALTER PROCEDURE sp_maxid
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
AS
select max(intEmployeeId) from EmployeeDetailsInfo
RETURN
u try this.............
Updated 18-Aug-11 20:02pm
v3
hai,
try this idea.,
use select query on find maximum id on that table and get it from front end.
code like this:
----------------
con.open();
string se="select max(uid) from tablename";
sqlcommand cmd=new sqlcommand(se,con);
int lastid=convert.ToInt32(cmd.executescalar());
con.close();
now you can get lastid value...
i hope this is useful to you...
take care bye bye
Quite interesting problem,
You'll have to do two things in InsertEmployee()
1: insert the employee
2: Get the ID of the last inserted employee
# 2 can be done this way by executing select query on the base of any information that userentered(but this info should be unique) or on the base of time at which employee entered the information
In this way you can get ID of last registered employee and from it you can get his information