Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Wednesday, November 10, 2010

AutoIncremented Number

public string NewRequestID()
{
string NewID = "";
SqlDataAdapter da = default(SqlDataAdapter);
DataTable dt = null;
da = new SqlDataAdapter("select top 1 code from EmpMaster order by code desc", con);
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count != 0)
{
string str = dt.Rows[0]["Code"].ToString();
int i = Convert.ToInt32(str.Substring(1));
NewID = (i + 1).ToString();
int start = NewID.Length + 1;
//Position from where 0 has to be inserted to the RequestID.
for (int j = start; j <= (str.Length - 1); j++)
{
NewID = "0" + NewID;
}
NewID = "A" + NewID;
}
else
{
NewID = "A000001";
}
return NewID;
}

No comments:

Post a Comment