|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Default value not being populated in datasetI 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 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/library/system.data.datacolumn.defaultvalue.aspx Maybe is that the solution for your problem. Cor Show quoteHide quote "Bob" <bduf***@sgiims.com> schreef in bericht news:ujhJ5TUmGHA.4716@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 > 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 Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:uMGCh$UmGHA.4952@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/library/system.data.datacolumn.defaultvalue.aspx > > Maybe is that the solution for your problem. > > Cor > > "Bob" <bduf***@sgiims.com> schreef in bericht > news:ujhJ5TUmGHA.4716@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 >> > >
ASP.NET web application - date conversions UK date format?
Building a single EXE file in VB 2005? What errors are not trappable? default in .NET byref or byval? Build Failed - 0 Errors Adding ActiveX controls at runtime and threading DataGridView row background color How to gain access to objet in different class ? Define a compilation switch Listbox help |
|||||||||||||||||||||||