I wanted to have a unique transaction id for each order placed on my system and it only increments once. this is the code that i am using. help me out to have the incrementation fixed.
string transactionCode;
con = new SqlConnection(@"Data Source=LAPTOP-KA7UGSG3;Initial Catalog=imsysdb;Integrated Security=True");
cmd = new SqlCommand("SELECT TransactionCode from tblOrders", con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
int code = int.Parse(dr[0].ToString()) + 1;
transactionCode = code.ToString("000");
}
else if (Convert.IsDBNull(dr))
{
transactionCode = ("001");
}
else
{
transactionCode = ("001");
}
lblTransactionCode.Text = transactionCode.ToString();
OUTPUT
|transaction code|
|001| |002| |002| |002|