Results 1 to 5 of 5

Thread: Add new column is DBNULL

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Add new column is DBNULL

    Hello,

    VS 2005

    I am developing the database application. This is a live database and is being used by the customer.

    I am to release a new version and I had to add new columns to fit the requirements DateStarted (DateTime), and TotalHours(Int) into a database table.

    There are already over a 1000 rows in this table. When the customer wants to look at a record in this table and insert the value into the text boxes (Front-end), when it gets to the DateStarted or TotalHours it comes up with a error message:
    "The value for column 'DateStarted' in table 'IncidentTask' is DBNull."

    The method for inserting is:
    Code:
      Me.dtDateStarted.Value = Me.DsIncidentsControl.IncidentTask(0).DateStarted
    What are the possible solutions to this problem? Would it mean checking for a DBNULL before displaying in the textboxes? Or updating the new column rows with an date:
    Code:
    UPDATE IncidentTask SET DateStarted = '1/1/2005' WHERE (DateStarted IS NULL)
    Many thanks for any suggestions,

    Steve
    steve

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add new column is DBNULL

    Putting fake data into a table sounds very wrong to me - it sounds as if the issue is with your application, not the database.

    I'm not sure where the issue is or how to fix it, but that is what you should be trying to do.

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Add new column is DBNULL

    How did you add the column to the table?

    Usually we do it with an ALTER TABLE command and at first allow nulls.

    Then update the column to a good value - such as 0 or "empty string" (or leave it null for a date).

    Then if appropriate we ALTER TABLE again and set it to not allow nulls.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Add new column is DBNULL

    Hello,

    I added the table by using management studio and right clicking on the table and select new column.

    I clicked allow nulls.

    Many thanks for any more help,
    steve

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Add new column is DBNULL

    If you are doing it in management studio then don't allow nulls but instead when you add the column give it a default value - such as "" for an empty string or 0 for a numeric column.

    That way the column is added to existing rows with this value.

    Then remove the default - since it's only purpose was to pre-load values into existing rows.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width