please,I want to generate number looks like 20100000000001 and increasing each time by one looks like 20100000000002 and so continue every time up by one at each execution, and only change in the year again, where it think 2010 is the year and changes each year new and start all over again 20110000000001,20110000000002......
thank you for your cooperation
Loading
Marimuthu ArigovindasamyPosted Jun 28, 2010, 2:45 AM
R u getting any error?. Can u check the mycmd variable value and num variable value.
string mycmd = "select IsNull(Max(depid),0) from employee";
SqlConnection connect = new SqlConnection(conString);
connect.Open();
SqlCommand cmd = new SqlCommand(mycmd, connect);
Int64 num = Convert.ToInt64(cmd.ExecuteScalar());
string s = Convert.ToString(num);
if (s.Substring(0, 4).Equals(DateTime.Now.Year.ToString()))
{
num++;
}
else
{
num = Convert.ToInt64(DateTime.Now.Year.ToString() + "0000000001");
}
textBox1.Text = num.ToString();
mycmd = "insert into employee (employeeid, depid) values (8, '" + @textBox1.Text + "')";
cmd = new SqlCommand(mycmd, connect);
cmd.ExecuteNonQuery();
MeshaPosted Jun 28, 2010, 3:19 AM
thank you for your cooperation
I know what is the problem that made the code does not process the increase and it will tell you Is that the machine that I work out where the problem in the process of responding to commands, and when tested in other machine to work properly
i'm pleased to know you and your cooperation
MeshaPosted Jun 28, 2010, 2:19 AM
thank you for your cooperation
but i don't know why the increasing don't done and i use this code in database also
there is any changing
look this
string mycmd = "select IsNull(Max(num),0) from Serial";
connect.Open();
SqlCommand cmd = new SqlCommand(mycmd,connect);
Int64 num = Int64.Parse(cmd.ExecuteScalar().ToString());
string s = Convert.ToString(num);
if(s.Substring(0,4).Equals(DateTime.Now.Year.ToString()))
{
num++;
}
else
{
num=Convert.ToInt64(DateTime.Now.Year.ToString()+"0000000001");
}
textBox1.Text = num.ToString();
mycmd="insert into Serial (num) values ('" + @textBox1.Text + "')";
cmd = new SqlCommand(mycmd,connect);
cmd.ExecuteNonQuery();
connect.close();
so please,can you tell me why??
Marimuthu ArigovindasamyPosted Jun 28, 2010, 12:25 AM
Int64 yearValue = 20090000000001;
string aa = Convert.ToString(yearValue);
if (aa.Substring(0, 4).Equals(DateTime.Now.Year.ToString()))
{
yearValue++;
}
else
{
yearValue = Convert.ToInt64(DateTime.Now.Year.ToString() + "0000000001");
}