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);

            SqlDataReader dtrCountPenalty = cmdCountPenalty.ExecuteReader();
            while (dtrCountPenalty.Read())

            SqlDataReader dtrCountBill = cmdCountBill.ExecuteReader();
            while (dtrCountBill.Read())

            SqlDataReader dtrCountPayment = cmdCountPayment.ExecuteReader();
            while (dtrCountPayment.Read())


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, learning, and sharing knowledge.