Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Member
 
Join Date: Jul 2008
Posts: 77
#1: Aug 8 '08
Hi all,
Please help me in this code:

txtLastNameFM.Text = IIf(dgFamilyMember.CurrentRow.Cells(3).Equals(Syst em.DBNull.Value), "", dgFamilyMember.CurrentRow.Cells(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.Cells(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.Cells(3).Value) to see if it is Null I need to fill txtlastname.text by "" otherwise I want to have the dgFamilyMember.CurrentRow.Cells(3).Value in that textbox.
Please help me.

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Aug 8 '08

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


You can't compare strings to DBNulls like that.
Member
 
Join Date: Jul 2008
Posts: 77
#3: Aug 8 '08

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


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

Please help me.
Member
 
Join Date: Jul 2008
Posts: 77
#4: Aug 8 '08

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


I found it.
I used IsDBNull(expression) before assigning to a string.
Reply