Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SqlHierarchyId insert

SqlHierarchyId insert

Scheduled Pinned Locked Moved Database
helpquestion
2 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mycroft Holmes
    wrote on last edited by
    #1

    What is the syntax for using a sQLParameter to insert a SqlHierarchyId. I'm stuck with the datatype to apply to the parameter object as I can't seem to get anything to support the SqlHierarchyId type. And my google mojo has completely let me down.

    			List lParams = new List();
    			SqlParameter oParam = new SqlParameter();
    			oParam.ParameterName = "@NodeKey";
    			oParam.Value = this.NodeKey;
    			oParam.SqlValue = this.NodeKey;
    			oParam.DbType = SqlHierarchyId;
    
    M 1 Reply Last reply
    0
    • M Mycroft Holmes

      What is the syntax for using a sQLParameter to insert a SqlHierarchyId. I'm stuck with the datatype to apply to the parameter object as I can't seem to get anything to support the SqlHierarchyId type. And my google mojo has completely let me down.

      			List lParams = new List();
      			SqlParameter oParam = new SqlParameter();
      			oParam.ParameterName = "@NodeKey";
      			oParam.Value = this.NodeKey;
      			oParam.SqlValue = this.NodeKey;
      			oParam.DbType = SqlHierarchyId;
      
      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      By using a varchar datatype for the insert parameter. It seems there is an implicit conversion from varchar to hierarchyid in SQL Server 2008

      			oParam = new SqlParameter();
      			oParam.ParameterName = "@NodeKey";
      			oParam.DbType.Equals(SqlDbType.VarChar);
      			oParam.Value = this.NodeKey.ToString();
      			oCmd.Parameters.Add(oParam);
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups