I have a CreatedOn field , datetime, which has GetDate() as the default
value. When I create a new record in the table itself, the field gets
populated OK, but when I try to create a new record with a Microsoft
datagridview control, I notice that the datecreated value does not get
created. It looks as if the datagridview insert statements override the
default value and prevent the default defined in the table to get written.
Any ideas on how to overcome this? I<ve looked in the dataridview controls
properties and the dataset properties for this table and don't find anything
simple to let me ensure that on an insert my default value defined in the
table is the one saved.
It looks like I will have to do something in SQL server itself.
Any help would be appreciated.
BobThis is not an engine issue. I suggest you post this to an ADO.NET group whe
re such experts
hopefully has some suggestions. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bob" <bdufour@.sgiims.com> wrote in message news:e%23bHrSUmGHA.4268@.TK2MSFTNGP05.phx.gbl...
>I have a CreatedOn field , datetime, which has GetDate() as the default val
ue. When I create a new
>record in the table itself, the field gets populated OK, but when I try to
create a new record with
>a Microsoft datagridview control, I notice that the datecreated value does
not get created. It
>looks as if the datagridview insert statements override the default value a
nd prevent the default
>defined in the table to get written.
> Any ideas on how to overcome this? I<ve looked in the dataridview controls
properties and the
> dataset properties for this table and don't find anything simple to let me
ensure that on an
> insert my default value defined in the table is the one saved.
> It looks like I will have to do something in SQL server itself.
> Any help would be appreciated.
> Bob
>|||It would be easier for us to assist you if you were to provide the table
DDL.
I suspect that the application/dataadapter/ADO is taking the current value
of the datagrid cell (probably an zero or empty string) and using that in
the INSERT command.
Default values ONLY occur IF no value is INSERTed. If an empty string or
zero is INSERTed, then it is accepted.
If you are unable to control this behaviour in the application, you may have
to create a INSERT Trigger that changes the zero/empty strings into
getdate().
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"Bob" <bdufour@.sgiims.com> wrote in message
news:e%23bHrSUmGHA.4268@.TK2MSFTNGP05.phx.gbl...
>I have a CreatedOn field , datetime, which has GetDate() as the default
>value. When I create a new record in the table itself, the field gets
>populated OK, but when I try to create a new record with a Microsoft
>datagridview control, I notice that the datecreated value does not get
>created. It looks as if the datagridview insert statements override the
>default value and prevent the default defined in the table to get written.
> Any ideas on how to overcome this? I<ve looked in the dataridview controls
> properties and the dataset properties for this table and don't find
> anything simple to let me ensure that on an insert my default value
> defined in the table is the one saved.
> It looks like I will have to do something in SQL server itself.
> Any help would be appreciated.
> Bob
>
No comments:
Post a Comment