I tried the example your directed me to and it worked, but the generated numbers are not starting like 001, 002
see code
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Customer_Search.aspx");
}
protected void btncode_Click(object sender, EventArgs e)
{
string previousIdQuery = "SELECT MAX(Receipt) UniqueId FROM TransID";
string newId = GenerateNewId(connStr, previousIdQuery);
txtcode.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);
}