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

前端 未结 11 1939
青春惊慌失措
青春惊慌失措 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:14

    I suppose you can do it like this:

    string accountNumber = DBSqlHelperFactory.ExecuteScalar(...) as string;
    

    If accountNumber is null it means it was DBNull not string :)

提交回复
热议问题