473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1.   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";
  2.  
  3.  try
  4.         {
  5.  OleDbCommand cmd=new OleDbCommand(selectstr,conn);
  6.         conn.Open();
  7.         DateTime tmpdate1 = DateTime.Parse(Request.QueryString["value1"]);
  8.         DateTime tmpdate2 = DateTime.Parse(Request.QueryString["value2"]);
  9.         cmd.Parameters.Add("@orderDate1",OleDbType.DBDate).Value = tmpdate1;
  10.         cmd.Parameters.Add("@orderDate2", OleDbType.DBDate).Value = tmpdate2;
  11.  
  12.             OleDbDataAdapter ada = new OleDbDataAdapter(cmd);
  13.             DataSet ds = new DataSet();
  14.             ada.Fill(ds);
  15.             ddlSearch.DataSource = ds;
  16.             ddlSearch.DataBind();
  17.  }
  18.         catch (Exception ex)
  19.         {
  20.             Response.Write(ex.Message);
  21.         }
  22.         conn.Close();
  23.  
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
Feb 13 '08 #1
4 1308
mentor
24
Request.QueryString["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.
Feb 13 '08 #2
Request.QueryString["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
Feb 13 '08 #3
mentor
24
No my value is in the format of dd/mm/yyyy
Are you sure
Expand|Select|Wrap|Line Numbers
  1. value1 = Request.QueryString["value1"] 
is in the format of dd/mm/yyyy ?
Feb 13 '08 #4
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
Feb 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jonathan | last post by:
Hi, i am having a hard time trying to convert my date. Here is my problem : I get an input date from a user in a form (in a asp:textbox control). The date is validated with the "dd/MM/yyyy"...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
2
by: Sterling Ledet | last post by:
I am trying to create a web service that takes a string from my web server in the following format: Mon, 6 Oct 2003 18:39:47 UTC and put's in a datetime so it can then be reformatted in C# as...
3
by: juli | last post by:
How can I convert string into a datetime? Thanks!
4
by: juli | last post by:
Good afternoon! I have an error while trying to convert to DateTime ,here is the code and the error: ArrayList al = new ArrayList(); temp_str=Line.Split(' '); al.Add(temp_str); //...
8
by: juli | last post by:
I am trying to convert an object of a class which is derived from collectionbase class.It's not working: while ((line = file.ReadLine()) != null && line.IndexOf(" ")!=-1) { al.Add(line); }...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
7
by: Filips Benoit | last post by:
Dear all, Tables: COMPANY: COM_ID, COM_NAME, ..... PROPERTY: PRP_ID, PRP_NAME, PRP_DATATYPE_ID, PRP_DEFAULT_VALUE ( nvarchar) COMPANY_PROPERTY: CPROP_COM_ID, CPROP_PRP_ID, CPROP_VALUE...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.