更新时间:2022-10-14 23:30:53
http://www.tutorialspoint.com/mysql/mysql- using-sequences.htm [ ^ 一>
Dear Frnds,
I have generate autogen id using mysql.. but not accept the charindex function.. please tell other method for autogen. following code..
<pre lang="xml">//MySqlCommand com = new MySqlCommand("SELECT isnull(Max(cast(substring(Reg_No,charindex('-',Reg_No)+1,len(Reg_No)) as int)),0)+1 FROM In_Patients", conn);
MySqlCommand com = new MySqlCommand("SELECT Max(Reg_No) FROM In_Patients", conn);
conn.Open();
Int32 no = Int32.Parse(com.ExecuteScalar().ToString()) + 1;
conn.Close();
string RNo = "REG" + DateTime.Now.Year + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd") + "-" + String.Format("{0:000}", no);
txtRegNo.Text = RNo;</pre>
With Regards,
Vino
http://www.tutorialspoint.com/mysql/mysql-using-sequences.htm[^]