Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to display data to datagrid from ms access which has the same date from label.text=datetime.now.toshortdatestring().

deeply appreciated!!!thanks
Posted
Comments
Kornfeld Eliyahu Peter 7-Dec-14 3:55am    
http://mattgemmell.com/what-have-you-tried/

C#
// you have date time string from toshortdatestring 
var dateString = DateTime.Now.ToShortDateString();
// you need to conver above string back to DateTime 
DateTime dt = DateTime.ParseExact(dateString, 
		System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern,
		System.Globalization.CultureInfo.CurrentCulture);
//now you can retrive data from your database as below by filtering using 
//where condition and parameter 
using (OleDbConnection  con = new OleDbConnection(strConnect))
{
	con.Open();
	OleDbDataAdapter da = new OleDbDataAdapter("SELECT * TABLENAME WHERE COLNAME= ?", con);
	da.SelectCommand.Parameters.AddWithValue("@Date", dt.Date);
	DataTable dt = new DataTable();
	da.Fill(dt);
	yourgridview.DataSource = dt;
}
 
Share this answer
 
Comments
markqui 15-Dec-14 22:11pm    
thank you

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