GETTING ERROR WHEN USE DATE TO SEARCH

marcel ethan

Total Post:105

Points:735
Posted by  marcel ethan
C# 
C#
 991  View(s)
Ratings:
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

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Getting Error When use Date to Search

    Hi Marcel,


    Try this in your sql query.

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

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!