title: Convert a string to a hierarchyid in C#
body: <p>I need to be able to convert a string to a hierarchyid in c#.net - I cannot use stored procedures.</p>
  
  <p>When I pass in the path (string) the query fails as the path is stored like this '/' instead of /</p>
  
  <p>Can I convert it to another type?</p>
  
  <pre><code>SqlCommand command = new SqlCommand("INSERT Structure (Path,Description,ParentID) " +
      "VALUES(" + path + ".GetDescendant(" + lastChildPath +
      ", NULL) " +
      ",@description, @parentId", _connection);
  </code></pre>
  
  <p><strong>-- BitKFu</strong></p>
  
  <p>I have added the and this is the sql query it produces:</p>
  
  <pre><code>CommandText = "INSERT Structure (Path,Description,ParentID) VALUES(CAST(/ AS hierarchyid).GetDescendant(NULL, NULL) ,@description, @parentId"
  </code></pre>
  
  <p>I get the following error: ex = {"Incorrect syntax near '/'."}</p>
  
  <p><strong>-- ck</strong></p>
  
  <p>This is what I am expecting</p>
  
  <pre><code>"INSERT Structure (Path,Description,ParentID) VALUES(/.GetDescendant(NULL, NULL) ,'Test', 1"
  </code></pre>
  
  <p><strong>-- Paul Ruane</strong></p>
  
  <p>I have looked at this page already but it didnt really help, unless I overlooked something?</p>
  
  <p>Thanks</p>
  
  <p>Clare</p>