Unable to cast object of type 'System.DBNull' to type 'System.String`

前端 未结 11 1710
青春惊慌失措
青春惊慌失措 2020-11-22 06:45

I got the above error in my app. Here is the original code

public string GetCustomerNumber(Guid id)
{
     string accountNumber = 
          (string)DBSqlHel         


        
11条回答
  •  孤独总比滥情好
    2020-11-22 07:13

    There is another way to workaround this issue. How about modify your store procedure? by using ISNULL(your field, "") sql function , you can return empty string if the return value is null.

    Then you have your clean code as original version.

提交回复
热议问题