trouble while storing date in access database

  • From: sameer manohtra <sameermanohtra@xxxxxxxxx>
  • To: programmingblind <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 25 Aug 2010 05:21:48 +0530

Hi guys, i’m  having trouble while  storing date in an access database.
The programming language is c# and database as said, is Microsoft access.

Could someone point out what wrong am I doing and what needs to be done?

I have a simple insert query that insert just 2 fields of the table.
I.E. name and date.

Consider the code:

String name = txtName.text;
DateTime date = convert.toDateTime (txtDate);


String insert = “insert into dateOfJoining(name, date) values('” +
name + “’, ‘” + date + “’”;

            OleDbCommand cmd1 = new OleDbCommand(insert, con);
            con.Open();

            cmd1.ExecuteReader();
            con.Close();

in this simple query, I get format exception in the date.
I’m pretty sure that the date entered in txtDate is correct and in a
proper MMDDYY format which I believe is default for access.
Though, I’ve tried with DDMMYY as well.

now, what wrong am I doing?
I’m so embarrass that I’m not able to do this extremely simple task.
Someone please help me.


Sameer.
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: