无法将‘System.DBNull’类型的对象转换为‘System.String’我在我的应用程序中得到了上面的错误。这是原始代码public string GetCustomerNumber(Guid id){
string accountNumber =
(string)DBSqlHelperFactory.ExecuteScalar(connectionStringSplendidmyApp,
CommandType.StoredProcedure,
"GetCustomerNumber",
new SqlParameter("@id", id));
return accountNumber.ToString();
}我用public string GetCustomerNumber(Guid id){
object accountNumber =
(object)DBSqlHelperFactory.ExecuteScalar(connectionStringSplendidCRM,
CommandType.StoredProcedure,
"spx_GetCustomerNumber",
new SqlParameter("@id", id));
if (accountNumber is System.DBNull)
{
return string.Empty;
}
else
{
return accountNumber.ToString();
}}有什么更好的办法吗?
3 回答
- 3 回答
- 0 关注
- 827 浏览
添加回答
举报
0/150
提交
取消