我有一个数据库表作为的DBNull错误快到了
FruitCrateTable FruitCrateID, FruitCrateName, FruitGarden
现在我还创建了一个存储过程作为,
CREATE procedure [dbo].[GetFruitCrate]
(
@FruitCrateID int,
@FruitCrateName varchar(222)
)
AS
SELECT
*
FROM
FruitCrateTable
WHERE
FruitCrateID = @FruitCrateID
and
FruitCrateName = @FruitCrateName
现在,当我尝试检查,如果FruitGarden为空或不使用数据访问,
我创建的行为的情况下,
public myDataAccess.DataAccess.GetFruitCrateRow fruitCrateRow;
//then
if (!string.IsNullOrEmpty(fruitCrateRow.FruitGarden))
{
//do something but i am getting error, how can i fix this issue ?
else { // do something else }
错误,
The value for column 'FruitGarden' in table 'GetFruitCrate' is DBNull.</message><full>System.Data.StrongTypingException: The value for column 'FruitGarden' in table 'GetFruitCrate' is DBNull. ---> System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.
我离开果园为空,因为它可以为null
更新
当我尝试fruitCrateRow.FruitGarden!= DBNull.Value我得到错误运算符'!='不能应用于类型'字符串'和'系统数据库'的操作数
你的存储过程是'[DBO] [GetFruitCrate]',但你打电话'GetFruitCrateRow'? –
@PatLillis我改名为我的场景 – Mathematics