Click here to Skip to main content
12,507,376 members (79,810 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello Friend

i have problem to count total record here is my code for count total record
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.
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 8-Nov-12 4:21am

1 solution

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

Solution 1

You have to remove the "COUNT(*)" and just use "*" for the query in the sql data adapter
  Permalink  
Comments
Yatin chauhan 8-Nov-12 10:38am
   
THX YOU I RESOLVE THIS.
THANK YOU SO MUCH
Marcus Kramer 8-Nov-12 13:56pm
   
+5. Good catch.
Mathlab 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2016
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