Conversion from type 'DBNull' to type 'String' is not valid.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sep410
    New Member
    • Jul 2008
    • 77

    Conversion from type 'DBNull' to type 'String' is not valid.

    Hi all,
    Please help me in this code:

    txtLastNameFM.T ext = IIf(dgFamilyMem ber.CurrentRow. Cells(3).Equals (System.DBNull. Value), "", dgFamilyMember. CurrentRow.Cell s(3).Value)

    this is an error I get:
    Conversion from type 'DBNull' to type 'String' is not valid.

    I know the value of the dgFamilyMember. CurrentRow.Cell s(3).Value= null but the first part of the iif returns false! What is wrong here?

    I need to check the value of dgFamilyMember. CurrentRow.Cell s(3).Value) to see if it is Null I need to fill txtlastname.tex t by "" otherwise I want to have the dgFamilyMember. CurrentRow.Cell s(3).Value in that textbox.
    Please help me.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    You can't compare strings to DBNulls like that.

    Comment

    • Sep410
      New Member
      • Jul 2008
      • 77

      #3
      I need to check the value of dgFamilyMember. CurrentRow.Cell s(3).Value) to see if it is Null I need to fill txtlastname.tex t by "" otherwise I want to have the dgFamilyMember. CurrentRow.Cell s(3).Value in that textbox.

      Please help me.

      Comment

      • Sep410
        New Member
        • Jul 2008
        • 77

        #4
        I found it.
        I used IsDBNull(expres sion) before assigning to a string.

        Comment

        Working...