Data Reader Returning null although it says it has an item there
<p>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 <code>Data is Null. This method or property cannot be called on Null values.</code></p>

<p>How can I check for null int hat line XML = XML + reader.GetString(0);? it is passing the while(reader.Read() &amp;&amp; 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?</p>

<p>Here is my code</p>

<pre><code>   SqlDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

        string XML = "";

        while (reader.Read() &amp;&amp; reader.HasRows)
        {
               XML = XML + reader.GetString(0); 
        }

        XML = "&lt;ProductList&gt;" + XML + "&lt;/ProductList&gt;";

        reader.Close();
        myConnection.Close();

        return XML;
</code></pre>
