title: How to send a Null value in xml string
body: <p>The RefNo column in SQL Server table is of datatype bigint, and can accept Nulls.
  I am saving multiple records via xml using c#. The code works good, but for a few records, the RefNo has to be null, and it is saving as 0 even when I comment the 'else' part in stringbuilder.</p>
  
  <p><strong>SQL:</strong></p>
  
  <pre><code>ALTER PROCEDURE SaveActivity
  @XMLData xml
  AS
  BEGIN
    IF @XMLData IS NOT NULL
      BEGIN
          CREATE TABLE #Temp(
              ActivityId uniqueidentifier,                
              RefNo int,
              Notes nvarchar(500)             
              );
  
      INSERT INTO tblActivityDetails(ActivityId,RefNo,Notes)        
        SELECT
          detail.query('ActivityId').value('.','uniqueidentifier') as ActivityId,
          detail.query('RefNo').value('.','int') as RefNo,
          detail.query('Notes').value('.','nvarchar(500)') as Notes           
        FROM
          @XMLData.nodes('/details/detail') AS xmlData(detail)
      END
  END
  </code></pre>
  
  <p><strong>C#:</strong></p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
  
  sb.AppendLine("&lt;?xml version=\"1.0\"?&gt;");
  sb.AppendLine("&lt;details&gt;")
  
  foreach(GridViewRow gr in gvActivity.Rows)
  {
      HiddenField hdRefNo = (HiddenField)gr.FindControl("hdRefNo");
      HiddenField hdNotes = (HiddenField)gr.FindControl("hdNotes");
  
      string sRefNo = hdRefNo.value.ToString()=="0" ? null : 
                      hdRefNo.value.ToString();
      sb.AppendLine("&lt;detail&gt;");
          sb.AppendLine("&lt;ActivityId&gt;"+ gActivityId.ToString() + "&lt;/ActivityId&gt;");
  
           if(sRefNo!="0")
             sb.AppendLine("&lt;RefNo&gt;"+ sRefNo + "&lt;/RefNo&gt;");
           else
             sb.AppendLine("&lt;RefNo&gt;&lt;/RefNo&gt;");
          sb.AppendLine("&lt;Notes&gt;"+ hdNotes.value.ToString() + "&lt;/Notes&gt;");
          sb.AppendLine("&lt;/detail&gt;");
  }
  sb.AppendLine("&lt;/details&gt;")
  </code></pre>