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

Total Post:105

Posted on    December-15-2013 11:53 PM

 C# C# 

 1 Reply(s)
 962  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();


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

        ddlOrderDate.DataSource = ds;

        ddlOrderDate.DataTextField = "Date";


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:412

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