Re: trouble while storing date in access database

  • From: "black ares" <matematicianu2003@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 25 Aug 2010 16:52:03 +0300

in fact
default for access is what is set in regional settings of windows.
There you must look.
For converting string to date and to be sure you optain what you want you must use
the datetime.parseexact
using a culture specific to the computer your program is running on.
So for example if in regional settings is set
yyyy-mm-dd
and you enter mm/dd/yyyy or dd/mm/yyyy
you will get errors.

----- Original Message ----- From: "Jacob Kruger" <jacobk@xxxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, August 25, 2010 6:00 AM
Subject: Re: trouble while storing date in access database


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


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

Other related posts: