Default value not being populated in dataset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob

    #1

    Default value not being populated in dataset

    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


  • Cor Ligthert [MVP]

    #2
    Re: Default value not being populated in dataset

    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" <bdufour@sgiims .com> schreef in bericht
    news:ujhJ5TUmGH A.4716@TK2MSFTN GP04.phx.gbl...[color=blue]
    >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
    >[/color]


    Comment

    • Bob

      #3
      Re: Default value not being populated in dataset

      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
      datatableAdapte rs 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]" <notmyfirstname @planet.nl> wrote in message
      news:uMGCh$UmGH A.4952@TK2MSFTN GP04.phx.gbl...[color=blue]
      > 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" <bdufour@sgiims .com> schreef in bericht
      > news:ujhJ5TUmGH A.4716@TK2MSFTN GP04.phx.gbl...[color=green]
      >>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
      >>datagridvie w 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
      >>[/color]
      >
      >[/color]


      Comment

      Working...