String was not recognized as a valid DateTime.
  • hi please when i want to add record in database i'm facing this error :String was not recognized as a valid DateTime.

    how i can resolve that :

    my code is that

    List ListT_Orders = new List();
    SqlConnection conx = new SqlConnection(ConfigurationManager.AppSettings["cnx"]);
    conx.Open();
    SqlCommand cmd = new SqlCommand(" select * from T_ORDER", conx);
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
    while (dr.Read())
    {

    T_ORDER TOrd = new T_ORDER();
    TOrd.ORDER_ID = dr[0].ToString();
    TOrd.USER_ID = dr[0].ToString();
    TOrd.CUSTOMER_ID = dr[0].ToString();
    if (!(dr["ORDER_DueDate"] is DBNull))
    {
    TOrd.ORDER_DueDate = Convert.ToDateTime(dr[0]);
    }
    ListT_Orders.Add(TOrd);


    }
    dr.Close();
    conx.Close();



    }
    return (ListT_Orders);

    my format date in table T_Order is that :DateTime('2013-03-01 00:00:00.000')

    thank you so much friends ;) .
  • 1 Comment sorted by
  • Vote Up0Vote Down Jaguar777Jaguar777
    51.00 Karma Accepted Answer
    Convert DateTime field in your code before sending it value to database.What is the value on dr[0] on debug mode?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Top Posters Weekly

Optimum Creative