I have a database table as
FruitCrateTable FruitCrateID, FruitCrateName, FruitGarden
Now I also created a Stored procedure as,
CREATE procedure [dbo].[GetFruitCrate]
(
@FruitCrateID int,
@FruitCrateName varchar(222)
)
AS
SELECT
*
FROM
FruitCrateTable
WHERE
FruitCrateID = @FruitCrateID
and
FruitCrateName = @FruitCrateName
Now when I try to check if FruitGarden is null or not using DataAccess,
I created instance of row as,
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 }
Error,
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'.
I left Fruit Garden as Null as it can be null
Update
when i try fruitCrateRow.FruitGarden != DBNull.Value I get Error Operator '!=' cannot be applied to operands of type 'string' and 'System.DBNull