Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
here is my code; i want to search from a dynamic date range where start range is selected from my DB and end range will be the date after 3 month of that starting range.

string sqlquery6 = "SELECT * FROM Bill_Details where PCID= '"+PCNo+"' order by Bill_Date";
            SqlDataAdapter adp6 = new SqlDataAdapter(sqlquery6, conn);
            DataTable tbl6 = new DataTable();
            adp6.Fill(tbl6);
            if (tbl6.Rows.Count > 0)
            {
                DateTime startrange = Convert.ToDateTime(tbl6.Rows[0][2].ToString());
                DateTime endrange = Convert.ToDateTime(startrange + 90);
                string sqlquery3 = "SELECT * FROM Bill_Details WHERE Bill_Date BETWEEN '" + startrange + "' AND '" + endrange + "' and PCID= '" + PCNo + "'";
                SqlDataAdapter adp3 = new SqlDataAdapter(sqlquery3, conn);
                DataTable tbl3 = new DataTable();
                adp3.Fill(tbl3);
                if (tbl3.Rows.Count > 0)
                {
                    int totbill = 0;
                    for (int i = 0; i < tbl3.Rows.Count; i++)
                    {
                        totbill = totbill + Convert.ToInt32(tbl3.Rows[i][0].ToString());
                    }

                    txttot.Text = totbill.ToString();
                }
                else
                {
                    txttot.Text = "0"; ;
                }
            }
Posted
Updated 12-Feb-12 19:13pm
v2

see this

System.DateTime today = System.DateTime.Now;
System.DateTime answer = today.AddDays(36);
System.Console.WriteLine("{0:dddd}", answer);

from : http://msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx[^]
 
Share this answer
 
Modify your query in such fashion
C#
"SELECT * FROM Bill_Details WHERE Bill_Date BETWEEN CONVERT(DATETIME,'" + startrange + "',103) AND CONVERT(DATETIME,'" + endrange  + "',103) and PCID= '" + PCNo + "'";


It will give you the expected result
 
Share this answer
 
in your query both for range you have used the same variable..
string sqlquery3 = "SELECT * FROM Bill_Details WHERE Bill_Date BETWEEN '" + startrange + "' AND '" + endrange  + "' and PCID= '" + PCNo + "'";
 
Share this answer
 

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