I have this code that increments numbers ones button recipt its clicked.
In a way to generate recipt numbers i use this code to generate numbers as recipt.
But once the numbers reach 100 it stops and it keeps repeating 100 instead 101,102, 103 etc.
Please how do i remove this limitation.
protected void btncallrecipt_Click(object sender, EventArgs e)
{
string previousIdQuery = "SELECT MAX(Receipt) UniqueId FROM TransID";
string newId = GenerateNewId(connStr, previousIdQuery);
txtrecipt.Text = newId;
txtpin.Text = newId;
string insertQuery = "INSERT INTO TransID VALUES(" + newId + ")";
using (SqlConnection con = new SqlConnection(connStr))
{
con.Open();
SqlCommand cmd = new SqlCommand(insertQuery, con);
cmd.ExecuteNonQuery();
con.Close();
}
}
private string GenerateNewId(string connection, string query)
{
string newId = string.Empty;
using (SqlConnection con = new SqlConnection(connection))
{
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string i = dr[0].ToString();
if (string.IsNullOrEmpty(i))
{
newId = "1";
}
else
{
int j = Convert.ToInt32(i);
j = j + 1;
newId = j.ToString();
}
}
con.Close();
}
return string.Concat(newId);
}
this is how it repeats 100
this is what its inserting 98 99 100 100 100 100 100