I have a code for autogenerated id. It is working, but my problem is the result. Numbers LDLB001 to LDLB009 is fine but when it reach numbers 10 onwards, the results are LDLB0010...LDLB0011 and so on. The result i want is LDLB010 but i can't do it. Here's the code. Hope you can help me.
private void autogen()
{
try
{
conn.Open();
String count = "SELECT count(*) + 1 as a FROM tbl_user";
MySqlDataAdapter sda = new MySqlDataAdapter(count, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
String strgen = dt.Rows[0]["a"].ToString();
MySqlCommand comm = new MySqlCommand("SELECT * FROM tbl_user WHERE userid = '" + "LDLB00" + strgen + "'", conn);
MySqlDataReader reader;
reader = comm.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
strgen = (int.Parse(strgen) + 1).ToString();
}
conn.Close();
lblUserID.Text = "LDLB00" + strgen;
}
catch (Exception et)
{
MessageBox.Show(et.Message);
}
}