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

后端 未结 8 730
攒了一身酷
攒了一身酷 2020-12-09 16:06

i am receiving this problem

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

Line 501: hfSupEmail.

8条回答
  •  春和景丽
    2020-12-09 16:48

    Apparently your dt.Rows(0)("SupEmail") is coming as NULL from DB and you cannot assign NULL to string property. Try replacing that line with:

    hfSupEmail.Value = If(IsDbNull(dt.Rows(0)("SupEmail")), String.Empty, dt.Rows(0)("SupEmail").ToString)
    

    The code checks if value is NULL and if it is - replaces it with empty string, otherwise uses original value.

提交回复
热议问题