我有一个数据库表
FruitCrateTable FruitCrateID, FruitCrateName, FruitGarden
现在我还创建了一个存储过程,
CREATE procedure [dbo].[GetFruitCrate]
(
@FruitCrateID int,
@FruitCrateName varchar(222)
)
AS
SELECT
*
FROM
FruitCrateTable
WHERE
FruitCrateID = @FruitCrateID
and
FruitCrateName = @FruitCrateName
现在,当我尝试使用 DataAccess 检查 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'.
我将 Fruit Garden 设为 Null,因为它可以为 null
更新
当我尝试fruitCrateRow.FruitGarden != DBNull.Value 我得到错误运算符'!='不能应用于'string'和'System.DBNull类型的操作数