hi my name is vishal.I was wondering on how to have trail of 5 zeros proceeding the value in my textbox in c# windows forms with sql server 2008.
Given below is my code in c# windows forms:
string dDID;
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
int autoGenId = -1;
cmd = new SqlCommand("Select max(agn) from dialyser;Select @autoGenId = SCOPE_IDENTITY();", conn);
cmd.Parameters.Add("@autoGenId", SqlDbType.Int).Direction = ParameterDirection.Output;
autoGenId = Convert.ToInt32(cmd.Parameters["@autoGenId"].Value);
if (autoGenId == 0)
{
dDID = "1";
}
else
{
dDID = autoGenId.ToString();
}
txtDID.Text = string.Format(0000 + dDID);
cmd.ExecuteNonQuery();the code executes with no problem but i get only 1 zero proceeding the value in my textbox in c# windows forms.
where agn is name of my field from table named:dialyser and which isauto-increment field of data type Int in my sql server 2008.
For example upon execution of code above the first time i get value in my textbox(txtDID) as01
But what i want is the value to appear in my textbox(txtDID) is upon execution as000001
I know this sounds silly but can anyone help me on how to achieve my required result?Can anybody help me please.Any hlp or guidance in solving of this problem would be greatly appreciated.
vishal