I have a C# application with a Transaction No. in windows form. I need to generate my transno. whenever i press the button to generate the transaction no. it will promp me a messagebox that says
I try to change the query from like '%" + sdate + "'" to like '" + sdate + "%'"
near 1 transno from tblcar where transno like '20200605%' at line 1
private void GetTransNo()
{
try
{
string sdate = DateTime.Now.ToString("yyyyMMdd");
string transno;
int count;
con.conDB.Open();
cmd = new MySqlCommand("SELECT TOP 1 transno from tblcart where transno like '" + sdate + "%'",con.conDB);
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
transno = dr[0].ToString();
count = int.Parse( transno.Substring(8, 4));
lblTransaction.Text = sdate + (count + 1);
}
else
{
transno = sdate + "1001";
lblTransaction.Text = transno;
}
dr.Close();
con.conDB.Close();
}
catch(Exception ex)
{
con.conDB.Close();
MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}