PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Can't get datetime value saved in access database

Reply

Can't get datetime value saved in access database

 
Thread Tools Rate Thread
Old 30-06-2003, 10:34 AM   #1
Gerben van Loon
Guest
 
Posts: n/a
Default Can't get datetime value saved in access database


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


  Reply With Quote
Old 02-07-2003, 11:40 AM   #2
Gerben van Loon
Guest
 
Posts: n/a
Default Re: Can't get datetime value saved in access database

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
> >
> >

>
>



  Reply With Quote
Old 02-07-2003, 12:07 PM   #3
Gerben van Loon
Guest
 
Posts: n/a
Default Re: Can't get datetime value saved in access database

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
> > >
> > >

> >
> >

>
>



  Reply With Quote
Old 12-08-2003, 01:53 PM   #4
Obe One
Guest
 
Posts: n/a
Default Re: Can't get datetime value saved in access database

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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off