Storing and retrieving dates from MS Access using C#

csharp , db Egypt
  • 10 years ago


    I am facing difficulty in storing date in MS Access using C# code. I have tried to save the DateTime object into the database. The column in the database was also of DateTime datatype. but I could not save the date. It gave me syntax error.

    Then I tried to save the date as a String. But this time the date got saved in the database as some decimal. Plz help me in this regard. How to save the date in MS Access.

    Thanking you,


  • 10 years ago


    Here's my code:

    I am using C#  in Visual Studio 2005.

                DateTime currentDate = DateTime.Now;
                String input = currentDate.ToShortDateString();
                string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\student.mdb";
                OleDbConnection myConnection = new OleDbConnection(connectionString);
                string query = "insert into student VALUES ("+ input +")";

                OleDbCommand myCommand = new OleDbCommand();
                myCommand.CommandText = query;
                myCommand.Connection = myConnection;




  • 10 years ago

     Thank you very much Bart. Its working fine now. I have one more problem. Is it possible to display multi-line list items in a list box in c# ? I need it in my application. Could you please help me out?



Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe