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? @@

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.