hello I am using a reader to get a XML from a stored procedure.. now the stored procedure returns null if it does not find anything .. in the case I am testing.. it should not return anything but my code is failing.. it says there is a row.. but then when it gets to the reader.GetString(0); it says Data is Null. This method or property cannot be called on Null values.
How can I check for null int hat line XML = XML + reader.GetString(0);? it is passing the while(reader.Read() && reader.HasRows) check.. when I debug it says there is an item but then when it gets to the line mentioned above it throws the Data is null error. How can I fix this?
Here is my code
SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
string XML = "";
while (reader.Read() && reader.HasRows)
{
XML = XML + reader.GetString(0);
}
XML = "<ProductList>" + XML + "</ProductList>";
reader.Close();
myConnection.Close();
return XML;
Use
IsDBNullfirst: