Re: trouble while storing date in access database

  • From: "Jacob Kruger" <jacobk@xxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 25 Aug 2010 05:00:31 +0200

Are you putting 's round the text based values in your string you're passing through to database etc.?


As in, the command string should preferably look like this:
insert into tblOne ([nameField], [dateField]) values ('my name', '2010/08/25');

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message ----- From: "sameer manohtra" <sameermanohtra@xxxxxxxxx>
To: "programmingblind" <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, August 25, 2010 1:51 AM
Subject: trouble while storing date in access database


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


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5394 (20100824) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 5394 (20100824) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



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

Other related posts: