0
        private void getCount()
        {
            SqlCommand cmdCountPenalty = new SqlCommand("SELECT PenaltyID FROM Penalty", conOOC);
            SqlCommand cmdCountBill = new SqlCommand("SELECT BillID FROM Bill", conOOC);
            SqlCommand cmdCountPayment = new SqlCommand("SELECT PaymentID FROM Payment", conOOC);
            conOOC.Open();

            SqlDataReader dtrCountPenalty = cmdCountPenalty.ExecuteReader();
            while (dtrCountPenalty.Read())
            {
                ++countPenalty;
            }
            dtrCountPenalty.Close();

            SqlDataReader dtrCountBill = cmdCountBill.ExecuteReader();
            while (dtrCountBill.Read())
            {
                ++countBill;
            }
            dtrCountBill.Close();

            SqlDataReader dtrCountPayment = cmdCountPayment.ExecuteReader();
            while (dtrCountPayment.Read())
            {
                ++countPayment;
            }
            dtrCountPayment.Close();

            conOOC.Close();

i'd declared countPenalty, countBill, countPayment as global variables and assgined = 1
(public static int countPenalty = 1, countBill = 1, countPayment = 1;)

every one counting were correct except countBill. The Result i get from countBill
(1st time = 1, 2nd time = 3). by right the 2nd time should be = 2. any idea what i am did wrong? @@

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by gahhon
0

Check your SQL statement. You are probably getting more than one result back so your While block is looping more than once.

0

i've solved the problem already.. since the i am calling this functions while Page_Load and i also call one more time when end-user click event. so i got double of it. so i seperate it. now it's fine already. TQ

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.