Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Frnds,

I have generate autogen id using mysql.. but not accept the charindex function.. please tell other method for autogen. following code..

C#
<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
Posted

1 solution

 
Share this answer
 
Comments
Member 10611310 13-Mar-14 5:10am    
i need char + no increment

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900