Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void cashreciept_Load(object sender, EventArgs e)
      {
            SqlDataAdapter da = new SqlDataAdapter("SELECT TOP 1 [Bill No] FROM cashreceipt ORDER BY [Bill No] DESC", sq.connection());
            DataTable dt1 = new DataTable();
            da.Fill(dt1);
            if (dt1.Rows.Count > 0)
            {
                billno = Convert.ToInt32(dt1.Rows[0][0]);
                
                billno +=1;
                txtbill.Text = billno.ToString();
            }
            else
            {
                string h = "1/1/1911";
                string c = "insert into cashreceipt values('" + 0 + "','" + 0 + "','" + 0 + "','" + 0 + "','" + 0 + "','" + 0 + "','" + h + "')";
                SqlCommand ccmd = new SqlCommand(c, sq.connection());
                ccmd.ExecuteNonQuery();
                SqlDataAdapter da1 = new SqlDataAdapter("SELECT TOP 1 [Bill No] FROM cashreceipt ORDER BY [Bill No] DESC", sq.connection());
                DataTable dt2 = new DataTable();
                da1.Fill(dt2);
                if (dt2.Rows.Count > 0)
                {
                    billno = Convert.ToInt32(dt2.Rows[0][0]);
                    billno  = billno+1;
                    txtbill.Text = billno.ToString();
                }

            }
        }
Posted
Updated 27-Dec-12 2:24am
v3

1 solution

Why? Probably, because you are storing your bill number as a string, not a numeric value.
So when it gets stored and the top value returned, the "9" value is return in preference to the "10"
Descending values as far as text is concerned:
C#
9
8
7
6
5
4
3
2
11
10
1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900