PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Can't get datetime value saved in access database
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Can't get datetime value saved in access database
![]() |
Can't get datetime value saved in access database |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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. "J. Kaul" <juergen.kaul@a-s.de> wrote in message news:bdtrvu$11e7r3$1@ID-175512.news.dfncis.de... > Hi Gerben, > I have solved the problem in an other project by converting: > > row.start = Convert.ToDateTime(startdate.ToString()); > > regards Jürgen > > "Gerben van Loon" <gerbenvl@home.nl> schrieb im Newsbeitrag > news:bdp3o6$d88$1@news3.tilbu1.nb.home.nl... > > 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 > > > > > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 van Loon" <gerbenvl@home.nl> wrote in message news:bdugah$15o$1@news3.tilbu1.nb.home.nl... > 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. > > "J. Kaul" <juergen.kaul@a-s.de> wrote in message > news:bdtrvu$11e7r3$1@ID-175512.news.dfncis.de... > > Hi Gerben, > > I have solved the problem in an other project by converting: > > > > row.start = Convert.ToDateTime(startdate.ToString()); > > > > regards Jürgen > > > > "Gerben van Loon" <gerbenvl@home.nl> schrieb im Newsbeitrag > > news:bdp3o6$d88$1@news3.tilbu1.nb.home.nl... > > > 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 > > > > > > > > > > > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 "Gerben van Loon" <gerbenvl@home.nl> wrote in message news:bduhu8$7p4$1@news3.tilbu1.nb.home.nl... > 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 van Loon" <gerbenvl@home.nl> wrote in message > news:bdugah$15o$1@news3.tilbu1.nb.home.nl... > > 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. > > > > "J. Kaul" <juergen.kaul@a-s.de> wrote in message > > news:bdtrvu$11e7r3$1@ID-175512.news.dfncis.de... > > > Hi Gerben, > > > I have solved the problem in an other project by converting: > > > > > > row.start = Convert.ToDateTime(startdate.ToString()); > > > > > > regards Jürgen > > > > > > "Gerben van Loon" <gerbenvl@home.nl> schrieb im Newsbeitrag > > > news:bdp3o6$d88$1@news3.tilbu1.nb.home.nl... > > > > 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 > > > > > > > > > > > > > > > > > > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

