Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello Friend

i have problem to count total record here is my code for count total record
C#
DateTime Todaydate = DateTime.Now;
        DateTime Pridaydate = DateTime.Now.AddDays(-5);
        int TotalPendingOrder = 0;
        SqlConnection con = new SqlConnection(ConnString);
        con.Open();
        string Qry = "select COUNT(*) from OrderMaster where OrderDate between CONVERT(CHAR(10),'" + Pridaydate + "',112) and CONVERT(CHAR(10),'" + Todaydate + "',112) and OrderStatus='Confirm'";
        SqlDataAdapter da = new SqlDataAdapter(Qry, con);
        DataTable dt = new DataTable();
        da.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            Summary.Visible = true;
            TotalPendingOrder = dt.Rows.Count;
            lblpending.Text = "There are " + " " + TotalPendingOrder.ToString() + " Orders Pending From Last 5 Days Please Shipped that order." + "<br/>" + " To Ship that order Please";
        }



it count only 1 record

when i run this code in sql it count 25 record here is sql query.
SQL
select COUNT(*) from OrderMaster where OrderDate between CONVERT(CHAR(10),(GETDATE()-5),112) and CONVERT(CHAR(10),GETDATE(),112) and OrderStatus='Confirm'


where i m wrong in coding to get records..
Thank You all..!!!
Posted

1 solution

You have to remove the "COUNT(*)" and just use "*" for the query in the sql data adapter
 
Share this answer
 
Comments
Yatin chauhan 8-Nov-12 10:38am    
THX YOU I RESOLVE THIS.
THANK YOU SO MUCH
fjdiewornncalwe 8-Nov-12 13:56pm    
+5. Good catch.
[no name] 8-Nov-12 16:05pm    
Thanks, I get a win every now and again

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