Click here to Skip to main content
14,883,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one drop down list where i select vendor name and in another two text boxes i enter two dates one is from date and another To date.When i click on Display order button,it should display all the orders placed between those two dates having selected vendor name.But i am getting no records found message what ever date i select.Please help me to resolve this.my button click code is below.please help me.

C#
protected void btndisplayordr_Click(object sender, EventArgs e)
    {


        DataTable dt = Periodicalcls.LoadPeriodicalprintdetails(txtvndrname.SelectedItem.Value, txtfrmdate.Text, txttodate.Text);
        if (dt.Rows.Count > 0)
        {
            lblmsg.Text = "";
            grdprinord.DataSource = dt;
            grdprinord.DataBind();
        }
        else
        {
            lblmsg.Text = "No Orders Found.";
        }


    }

C#
public static DataTable LoadPeriodicalprintdetails(string p, string p_2, string p_3)
   {
       try
       {
           return clsDbCommon.GetDataTable("[Lib_selectperioprintdetails]", new Object[] { "@VendorName", "@OrderDate", "@OrdDate" }, new Object[] { p, p_2, p_3 });
       }
       catch
       {
           throw;
       }
   }
Posted
Comments
pradiprenushe 13-Aug-13 12:32pm
   
What problem you are facing? How you are writing query/sp? What is your table column types for date?
kishore sharma 14-Aug-13 1:48am
   
need more details, how is your query?

Instead of passing Date as a string, pass as Datetime
   
v2
This may also help you..

SQL
select * from yourtablename where
(CAST(CONVERT(varchar(10), your column name of date , 101) AS datetime) <= CAST(CONVERT(varchar(10), todate, 101) AS datetime)) 
	AND (CAST(CONVERT(varchar(10), your column name of date , 101) AS datetime) <= CAST(CONVERT(varchar(10), fromdate, 101) AS datetime))


regards...:)
   
v3
C#
public DataTable Date_Select_ByDate(String vendorName,String d1,String d2)
{
     DateTime D1=Convert.ToDateTime(d1);
     DateTime D2=Convert.ToDateTime(d2);
     DB_Connection();
     DataSet DS = new DataSet();
     string Date_All = "";
    Date_All = "SELECT  VendorName,CONVERT(char(10),OrderDate, 103) AS OrderDate,CONVERT(char(10),OrdDate, 103) AS OrdDate FROM Lib_selectperioprintdetails where VendorName='"+vendorName+"' OrderDate between '" + D1 + "' and '" + D2 + "'";
            SqlDataAdapter DA = new SqlDataAdapter(Date_All, con);
            
     DA.Fill(DS);
     DataTable DT = DS.Tables[0];
     return DT;

        }
   
try
C#
select * from table where datecol>='"+fromdate.ToStrong("dd-mm-yyyy")+"' and datecol<'"+todate.ToString("dd-mm-yyyy")+"'
   
v2
Comments
Member 12360714 1-Mar-16 4:05am
   
@Maciej Los ,ToString The method ToString(String) is undefined for the type Date

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