Board index » delphi » Help!! Updating a DB field through FIELDS[x]

Help!! Updating a DB field through FIELDS[x]

I'm creating a table that will have a time stamp as part of the key.  I do
not want the users to have to enter a unique time date.  So I was going to
use the NOW system value and move it into the time stamp field in code as
follows.

Table1.Field[1] := Now;

Well it looks nice but I get a conflict of types.
 Table1.Filed[1] is of type TField
 Now is of type TDateTime

How do I resolve this situation.  This is my first attempt at a Delphi app
so I would appreciate any help.

Thank you
Mike

 

Re:Help!! Updating a DB field through FIELDS[x]


Quote
Mike Stuntz wrote:

> I'm creating a table that will have a time stamp as part of the key.  I do
> not want the users to have to enter a unique time date.  So I was going to
> use the NOW system value and move it into the time stamp field in code as
> follows.

> Table1.Field[1] := Now;

> Well it looks nice but I get a conflict of types.
>  Table1.Filed[1] is of type TField
>  Now is of type TDateTime

> How do I resolve this situation.  This is my first attempt at a Delphi app
> so I would appreciate any help.

> Thank you
> Mike

Table1.Field[1].Value := Now; (Delphi 2)
Table1.Fields[1].AsDateTime := Now; (Delphi 1 or 2)

It's even better if you define persistent fields w/ the field editor:
Table1MYDATE.Value := Now;

-Bryan

Re:Help!! Updating a DB field through FIELDS[x]


Quote
In article <01bbed01$1ec68ee0$c4b5b8c7@mstuntz> "Mike Stuntz" <mstu...@fullfeed.com> writes:
>I'm creating a table that will have a time stamp as part of the key.  I do
>not want the users to have to enter a unique time date.  So I was going to
>use the NOW system value and move it into the time stamp field in code as
>follows.
>Table1.Field[1] := Now;
>Well it looks nice but I get a conflict of types.
> Table1.Filed[1] is of type TField
> Now is of type TDateTime
>How do I resolve this situation.  This is my first attempt at a Delphi app
>so I would appreciate any help.

Try this:               Table1.Field[1].Value := Now

Now try this:   (smack!) "Doh!!"    ;-)

Actually, don't feel rained on -- we've all done it, we all do it.  But the
key is ".value" -- a method call to refer to the value of the database field
referred to by the TField object.

/mr/

Re:Help!! Updating a DB field through FIELDS[x]


Quote
>I'm creating a table that will have a time stamp as part of the key.  I do
>not want the users to have to enter a unique time date.  So I was going to
>use the NOW system value and move it into the time stamp field in code as
>follows.
>Table1.Field[1] := Now;
>Well it looks nice but I get a conflict of types.
> Table1.Filed[1] is of type TField
> Now is of type TDateTime
>How do I resolve this situation.  This is my first attempt at a Delphi app
>so I would appreciate any help.

--- gentlebeings:

Please note the database-oriented nature of this post.  And then notice the
extremely long newsgroup list.  Some of these newsgroups I didn't even know
existed... but there are quite a few!

Two things to bear in mind:  most of us read all of these, but if we are new
and looking only for a particular topic we tend to focus on one.  Each one is
very topic specific and designed so to be.  The idea is to reduce traffic.  
Therefore, please be judicious in where you choose to post.  Your message WILL
be read.

Second, get to know "www.dejanews.com."  It's a database of recent news
postings and follow-ups, and a dynamite resource to tap into when you think
"someone around here's done this before..." or "is this a frequently asked
question and I just don't know it?"

I intend this to be instructive and helpful and not a slam.  Please...

/mr/

Re:Help!! Updating a DB field through FIELDS[x]


Quote
>I'm creating a table that will have a time stamp as part of the key.  I do
>not want the users to have to enter a unique time date.  So I was going to
>use the NOW system value and move it into the time stamp field in code as
>follows.
>Table1.Field[1] := Now;
>Well it looks nice but I get a conflict of types.
> Table1.Filed[1] is of type TField
> Now is of type TDateTime
>How do I resolve this situation.  This is my first attempt at a Delphi app
>so I would appreciate any help.

--- gentlebeings:

Please note the database-oriented nature of this post.  And then notice the
extremely long newsgroup list.  Some of these newsgroups I didn't even know
existed... but there are quite a few!

Two things to bear in mind:  most of us read all of these, but if we are new
and looking only for a particular topic we tend to focus on one.  Each one is
very topic specific and designed so to be.  The idea is to reduce traffic.  
Therefore, please be judicious in where you choose to post.  Your message WILL
be read.

Second, get to know "www.dejanews.com."  It's a database of recent news
postings and follow-ups, and a dynamite resource to tap into when you think
"someone around here's done this before..." or "is this a frequently asked
question and I just don't know it?"

I intend this to be instructive and helpful and not a slam.  Please...

/mr/

Re:Help!! Updating a DB field through FIELDS[x]


Quote
"Mike Stuntz" <mstu...@fullfeed.com> wrote:
>I'm creating a table that will have a time stamp as part of the key.  I do
>not want the users to have to enter a unique time date.  So I was going to
>use the NOW system value and move it into the time stamp field in code as
>follows.
>Table1.Field[1] := Now;
>Well it looks nice but I get a conflict of types.
> Table1.Filed[1] is of type TField
> Now is of type TDateTime
>How do I resolve this situation.  This is my first attempt at a Delphi app
>so I would appreciate any help.

You have to use Table1.Field[1].AsDateTime := Npw;

There is also an AsFloat, AsString etc. Check the helpfiles.

Re:Help!! Updating a DB field through FIELDS[x]


Quote
Bryan Keller wrote:

> Mike Stuntz wrote:

> > I'm creating a table that will have a time stamp as part of the key.  I do
> > not want the users to have to enter a unique time date.  So I was going to
> > use the NOW system value and move it into the time stamp field in code as
> > follows.

> > Table1.Field[1] := Now;

> > Well it looks nice but I get a conflict of types.
> >  Table1.Filed[1] is of type TField
> >  Now is of type TDateTime

> > How do I resolve this situation.  This is my first attempt at a Delphi app
> > so I would appreciate any help.

> > Thank you
> > Mike

> Table1.Field[1].Value := Now; (Delphi 2)
> Table1.Fields[1].AsDateTime := Now; (Delphi 1 or 2)

> It's even better if you define persistent fields w/ the field editor:
> Table1MYDATE.Value := Now;

> -Bryan

My preference is table1.fieldbyname('DateTimeStamp').AsDateTime:=Now;

Crystal clear.

Dunc.
dmarg...@scomhbr3.telstra.com.au

Re:Help!! Updating a DB field through FIELDS[x]


Quote
"Mike Stuntz" <mstu...@fullfeed.com> wrote:
>I'm creating a table that will have a time stamp as part of the key.  I do
>not want the users to have to enter a unique time date.  So I was going to
>use the NOW system value and move it into the time stamp field in code as
>follows.
>Table1.Field[1] := Now;
>Well it looks nice but I get a conflict of types.
> Table1.Filed[1] is of type TField
> Now is of type TDateTime
>How do I resolve this situation.  This is my first attempt at a Delphi app
>so I would appreciate any help.

You have to use Table1.Field[1].AsDateTime := Npw;

There is also an AsFloat, AsString etc. Check the helpfiles.

Other Threads