I'm doing a simple program that needs DOB in it. I'm now stuck at the part where I have to retrieve the DOB out from the access database. The coding I need to use to retrieve is DateTime.Day, DateTime.Month and DateTime.Year.
Can someone please help? Any ideas....
Thank you.
Santhosh NPosted Jan 4, 2010, 3:12 AM
DataReader is used to retrive the records from any database and MS Access as well in your case...
You could try and let me know for any problems or else you can mark my ans as ACCPETED
Nur FasihaPosted Jan 4, 2010, 1:54 AM
Santhosh NPosted Jan 4, 2010, 1:51 AM
string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\Northwind.mdb";
OleDbConnection conn = new OleDbConnection(connectionString);
string sql = "SELECT colList FROM tablename where your cond";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader reader;
reader = cmd.ExecuteReader();
while (reader.Read())
{
DateTime dt = Convert.ToDateTime(reader.GetString(0));
int yr = dt.Year;
int mn = dt.Month;
int dy = dt.Day
}
reader.Close();
conn.Close();