且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自动生成id错误

更新时间: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(&quot;SELECT  Max(Reg_No) FROM In_Patients&quot;, conn);
conn.Open();
Int32 no = Int32.Parse(com.ExecuteScalar().ToString()) + 1;
conn.Close();
string RNo = &quot;REG&quot; + DateTime.Now.Year + DateTime.Now.ToString(&quot;MM&quot;) + DateTime.Now.ToString(&quot;dd&quot;) + &quot;-&quot; + String.Format(&quot;{0:000}&quot;, no);
txtRegNo.Text = RNo;</pre>



With Regards,
Vino

http://www.tutorialspoint.com/mysql/mysql-using-sequences.htm[^]