Home > DeveloperSection > Forums > Getting Error When use Date to Search
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    December-15-2013 11:53 PM

 C# C# 
Ratings:


 1 Reply(s)
 724  View(s)
Rate this:

cmdDateReceivingStock = new SqlCommand("Select Distinct Date FROM

        OrderDetails WHERE item_Received ='No'", conStock);

        SqlDataAdapter da = new SqlDataAdapter(cmdDateReceivingStock);

        DataSet ds = new DataSet();

        da.Fill(ds);

        ddlOrderDate.DataTextFormatString = "{0:dd-MM-yyyy}";

        ddlOrderDate.DataSource = ds;

        ddlOrderDate.DataTextField = "Date";

        ddlOrderDate.DataBind();

After I success convert the date into dropdownlist,but I getting this error"Conversion failed when converting date and/or time from character string." when I use the date to retrieve data from database



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-16-2013 12:44 AM

Hi Marcel,

Try this in your sql query.

 cmdDateReceivingStock = new SqlCommand("Select Distinct CONVERT(VARCHAR,Date,103) FROM

        OrderDetails WHERE item_Received ='No'", conStock);

Don't want to miss updates? Please click the below button!

Follow MindStick