Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
  
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 27-Dec-12 0:32am
Edited 27-Dec-12 2:24am
ridoy51.9K
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
9
8
7
6
5
4
3
2
11
10
1
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100