Convertion of string to datetime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agarwalsunitadhn
    New Member
    • Jan 2008
    • 82

    Convertion of string to datetime

    hi..

    Currently i am facing a problem. I had a form containing two text boxes and in these two textboxes user fill up the date.
    and as per user's date i have to search in the data from the database in between these two dates. i passed these two values as value1 and value2 through querystring in other page where i have to show the search results

    I am using ms-access as backend and visual studio 2005 and language used is c#.

    i had used following code
    Code:
      string selectstr = "select cl.cId,cl.cName,od.orderId,od.orderDate,od.specifiedAmount,od.paidAmount from ClientDetails cl,OrderDetails od where cl.cId=od.cId and od.orderDate between @orderDate1 and @orderDate2 order by od.orderId desc";
    
     try
            {
     OleDbCommand cmd=new OleDbCommand(selectstr,conn);
            conn.Open();
            DateTime tmpdate1 = DateTime.Parse(Request.QueryString["value1"]);
            DateTime tmpdate2 = DateTime.Parse(Request.QueryString["value2"]);
            cmd.Parameters.Add("@orderDate1",OleDbType.DBDate).Value = tmpdate1;
            cmd.Parameters.Add("@orderDate2", OleDbType.DBDate).Value = tmpdate2;
           
                OleDbDataAdapter ada = new OleDbDataAdapter(cmd);
                DataSet ds = new DataSet();
                ada.Fill(ds);
                ddlSearch.DataSource = ds;
                ddlSearch.DataBind();
     }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            conn.Close();
    where ddlSearch is a datagrid

    i got the following error:
    String was not recognized as a valid DateTime.

    Please give me suggestion that how can i debug this error.
    thanks in advance for your suggestions
  • mentor
    New Member
    • Mar 2007
    • 24

    #2
    Request.QuerySt ring["value1"] may cause problem. make sure the querystring value1 is in correct datatime format.

    Also you should pay attention to urlEcond to get some proper character.

    Suppose to set value1 ="2008-02-13", it should be ok.

    Comment

    • agarwalsunitadhn
      New Member
      • Jan 2008
      • 82

      #3
      Originally posted by mentor
      Request.QuerySt ring["value1"] may cause problem. make sure the querystring value1 is in correct datatime format.

      Also you should pay attention to urlEcond to get some proper character.

      Suppose to set value1 ="2008-02-13", it should be ok.
      No my value is in the format of dd/mm/yyyy

      Comment

      • mentor
        New Member
        • Mar 2007
        • 24

        #4
        Originally posted by agarwalsunitadh n
        No my value is in the format of dd/mm/yyyy
        Are you sure
        Code:
        value1 = Request.QueryString["value1"]
        is in the format of dd/mm/yyyy ?

        Comment

        • agarwalsunitadhn
          New Member
          • Jan 2008
          • 82

          #5
          i solved the above problem but in the output i got the following data

          2/13/2008 12:00:00 AM

          but i want the date in the format of dd/mm/yyyy and i dnt want to display time.
          can anyone solve my problem

          Comment

          Working...