title: Inserting NULL into DataTable
body: <p>Morning (in RSA at least),</p>
  
  <p>I'm trying to create a data driven menu, using data from a self-referencing table to create a (2-level) hierarchical structure. Example Data is:</p>
  
  <pre><code>MenuID  ParentID  Text      Url      CSS
  1       Null      Top                topCSS
  2       Null      Second             secCSS
  3       1         abc       z.aspx   abcCSS
  4       1         def       y.aspx   abcCSS
  5       2         ghi       x.aspx   defCSS
  </code></pre>
  
  <p>I'm using LINQ to Entities to get this data.  Then I populate a DataTable, then populate a DataSet and then create a DataRelation before converting it to XML to use in a xmlDataSource where it gets transformed for use as the Menu's DataSource.</p>
  
  <p>I must admit I've taken a lot of code from these Forums, and it <em>should</em> work.  Except the transform requires a NULL value in ParentID to indicate a top-level menu item, but I can't insert a NULL into the DataTable.  Code is below:</p>
  
  <pre><code>        using (var cntIuvo = new iuvocexi_dbEnts())
          {
              var b = (from a in cntIuvo.MenuNavs select a);
              DataTable myTB = new DataTable();
              myTB.Columns.Add("MenuID");
              myTB.Columns.Add("ParentID");
              myTB.Columns.Add("url");
              myTB.Columns.Add("CSS");
              DataRow myDR;
  
              foreach (var rec in b)
              {
                  myDR = myTB.NewRow();
                  myDR["MenuID"] = rec.MenuID;
                  myDR["ParentID"] = rec.ParentID;  // error is generated here
                  myDR["url"] = rec.url;
                  myDR["CSS"] = rec.CSS;
                  myTB.Rows.Add(myDR);
              }
  
              DataSet ds = new DataSet(); 
              ds.Tables.Add(myTB);
              ds.DataSetName = "Menus";
              ds.Tables[0].TableName = "Menu";
              DataRelation relation = new DataRelation("ParentChild", ds.Tables["Menu"].Columns["MenuID"], ds.Tables["Menu"].Columns["ParentID"], true);
              relation.Nested = true;
              ds.Relations.Add(relation);
              xmlDataSource1.Data = ds.GetXml();
              if (Request.Params["Sel"] != null)
                  Page.Controls.Add(new System.Web.UI.LiteralControl("You selected " +
                    Request.Params["Sel"]));
          }
  </code></pre>
  
  <p>My question is:  How do I insert NULL into the DataTable, or, failing that, how do I get the LINQ to Entities to populate a DataTable/DataSet, or, failing that how do I set up the Transform to allow for (say) a 0 instead of NULL.</p>
  
  <p>Transform.xslt is below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" indent="yes" encoding="utf-8"/&gt;
  
    &lt;!-- Replace root node name Menus with MenuItems
     and call MenuListing for its children--&gt;
    &lt;xsl:template match="/Menus"&gt;
      &lt;MenuItems&gt;
        &lt;xsl:call-template name= "MenuListing" /&gt;
      &lt;/MenuItems&gt;
    &lt;/xsl:template&gt;
  
    &lt;!-- Allow for recursive child nodeprocessing --&gt;
    &lt;xsl:template name="MenuListing"&gt;
      &lt;xsl:apply-templates select ="Menu" /&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="Menu"&gt;
      &lt;MenuItem&gt;
        &lt;!-- Convert Menu child elements to MenuItem attributes --&gt;
        &lt;xsl:attribute name="Text"&gt;
          &lt;xsl:value-of select="Text"/&gt;
        &lt;/xsl:attribute&gt;
        &lt;xsl:attribute name="ToolTip"&gt;
          &lt;xsl:value-of select="Text"/&gt;
        &lt;/xsl:attribute&gt;
        &lt;xsl:attribute name="NavigateUrl"&gt;
          &lt;xsl:text&gt;?Sel=&lt;/xsl:text&gt;
          &lt;xsl:value-of select = "url"/&gt;
        &lt;/xsl:attribute&gt;
  
        &lt;!-- Recursively call MenuListing forchild menu nodes --&gt;
         &lt;xsl:if test="count(Menu) &gt;0"&gt;
           &lt;xsl:call-template name="MenuListing" /&gt;
         &lt;/xsl:if&gt;
      &lt;/MenuItem&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Thank you very much for your attention so far!</p>
  
  <p>Regards</p>
  
  <p>Paul</p>