Can't get datetime value saved in access database

  • Thread starter Thread starter Gerben van Loon
  • Start date Start date
G

Gerben van Loon

Hi,

I'm trying to save a datetime value in an access datetime field. But weird
enough it only saves the date and not the time. I'm using the folowing piece
of code:

//Compose date
string datetemp;
datetemp = "28-6-2003 8:00:00";
DateTime startdate = DateTime.Parse(datetemp);

//Add to dbase
DStest.testRow row = DStest1.test.NewtestRow();
row.start = startdate;
DStest1.test.AddtestRow(row);
DAtest.Update(DStest1);

//Ceck or variable had the time in it
lblDisplayDate.Text = startdate.ToString(); //label shows date and time!

This last line of code displays me the date and also the time, but in the
dbase there is only the date. The dbase should be ok, because I can manualy
enter the datetime value I used in the code. Anybody a solution for this
problem?

thanks,

Gerben
 
Hi Jurgen,

Thanks for your reaction, but stil can't get it working. Even with your
solution it only saves the date in the access database. Code works fine on a
SQL database though, triple checked the date field in my access database and
in the dataset, and it both says it's a datetime. Anybody know what I'm
doing wrong?

greets Gerben.
 
Ah already found what the problem was:

The parameters the data-adapter generated for me where 'wrong'. For an
access datetime field it generates a parameter of the type
"System.Data.OleDb.OleDbType.DBDate" type, which should accept a datetime
value, but apparently doesn't. Changed the type to
"System.Data.OleDb.OleDbType.Date"

A bit weird but now the code works fine!

thanks for your help,

greets Gerben
 
Gerben,

thanks for the tip which solved also my problem. This tip solves the problem
described by Stephen Hanna in this forum thread with subject "Access
Database Updates".

-- Obe
 
Back
Top