Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string n = dateTimePicker1.Value.ToString("yyyy-MM-dd");
DateTime thedate=Convert.ToDateTime(n);

after converting datetime i cannot use this "thedate" into c# sql query because in my database i want to fetch my data according datewise how could i do this pls suggest me





my query for fetching data is this............


dt = obj.GetDataTable("SELECT * from mobilesubscriberdata1 where m_date='"+n+'");


if there is any correction then pls suggest me where i can do the changes,,,,,,
Posted

Feels like you have asked this question before.

C#
string cmd = String.Format("SELECT * from mobilesubscriberdata1 where m_date='{0}'", dateTimePicker1.Value.ToString("yyyy-MM-dd"));
dt = obj.GetDataTable(cmd);


Make sure the date format "yyyy-MM-dd" matches the expected date format of your database.
You also need to consider the locale used by the database, if you have databases in different parts of the world.

Custom Date and Time Format Strings[^]
 
Share this answer
 
Comments
Member 10891595 14-Jul-14 0:57am    
thanks a lot
i have done it
Hi,

Use below query

C#
dt = obj.GetDataTable("SELECT * from mobilesubscriberdata1 where Convert(varchar(11),m_date,113)='"+Convert(varchar(11),n,113)+'");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900