468,720 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

Default value not being populated in dataset

Bob
I have a CreatedOn field , datetime, which has GetDate() as the default
value in SQL server 2000 table. When I create a new record in the table
itself in enterprise manager, 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 overrides 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 datagridview 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.

Any help would be appreciated.

Bob
Jun 26 '06 #1
2 3028
Bob,

AFAIK is the defaultvalue for the DataBase never set for the datatable (for
sure not in version 1.x). Maybe you find that strange, but Net should work
on more databases than only those from Microsoft.

You can however create in your datatables as well a default.

http://msdn2.microsoft.com/en-US/lib...aultvalue.aspx

Maybe is that the solution for your problem.

Cor

"Bob" <bd*****@sgiims.com> schreef in bericht
news:uj**************@TK2MSFTNGP04.phx.gbl...
I have a CreatedOn field , datetime, which has GetDate() as the default
value in SQL server 2000 table. When I create a new record in the table
itself in enterprise manager, 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 overrides 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 datagridview
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.

Any help would be appreciated.

Bob

Jun 26 '06 #2
Bob
Its a solution but it goes against the most basic rules of using RDBMS that
is, make the database do all the work that you can have it do, so that your
default values and validations are centralized in one location and you DO
NOT do that in your application code.
The fact that .NET works with many different databases is a weak excuse for
not having completed its development right.
If there is this problem that is known there should be a property in the
datatableAdapters or in the dataset definitions, somewhere where it makes
sense and is easily accessible to the developper, to force the default value
of a new column in a dataset or table adapter. There isn't. That a table
adapter should overwrite the default values of the database is stupid in the
first place. The .Net framework could look in the metadata of the tables
being used and find if there is a default value for a column, if there is it
should just not include these fields in the autogenerated insert statement.
Then you would not be getting a null value overwriting your database
defaults.
Just another example of halfbaked reasoning by Microsoft, Oh well. Maybe
sometime in the future they'll get it right and put the emphasis where its
due. On the reliability of the data, instead of on all the unecessary
glitter of so-called userfriendly interfaces.

Anyways, Thanks Cor

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uM**************@TK2MSFTNGP04.phx.gbl...
Bob,

AFAIK is the defaultvalue for the DataBase never set for the datatable
(for sure not in version 1.x). Maybe you find that strange, but Net should
work on more databases than only those from Microsoft.

You can however create in your datatables as well a default.

http://msdn2.microsoft.com/en-US/lib...aultvalue.aspx

Maybe is that the solution for your problem.

Cor

"Bob" <bd*****@sgiims.com> schreef in bericht
news:uj**************@TK2MSFTNGP04.phx.gbl...
I have a CreatedOn field , datetime, which has GetDate() as the default
value in SQL server 2000 table. When I create a new record in the table
itself in enterprise manager, 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 overrides 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 datagridview
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.

Any help would be appreciated.

Bob


Jun 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike Gage | last post: by
7 posts views Thread by NCrum | last post: by
1 post views Thread by Amadelle | last post: by
1 post views Thread by Jon S via DotNetMonster.com | last post: by
4 posts views Thread by rn5a | last post: by
1 post views Thread by Mark Baldwin | last post: by
7 posts views Thread by =?Utf-8?B?Tmljb2xhcw==?= | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.