自动生成id错误 [英] Autogenerate id Error
本文介绍了自动生成id错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,
我使用mysql生成autogen id但不接受charindex函数..请告诉autogen的其他方法。以下代码..
< 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; + 字符串 .Format(& quot; { 0 : 000 }& quot;,no);
txtRegNo.Text = RNo; < / pre >
问候,
Vino
解决方案
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[^]
这篇关于自动生成id错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文