自动生成id错误 [英] Autogenerate id Error

查看:85
本文介绍了自动生成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(&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[^]


这篇关于自动生成id错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆