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
  1. Home
  2. General Programming
  3. C#
  4. Passing a table (DataTable) value as a parameter to stored procedure

Passing a table (DataTable) value as a parameter to stored procedure

Scheduled Pinned Locked Moved C#
databasesql-serversysadminhelp
2 Posts 1 Posters 0 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.
  • S Offline
    S Offline
    sanjubaba
    wrote on last edited by
    #1

    Hi,    I am trying to pass a datatable as a parameter to a stored procedure. my sql server is 2008. Also my database transactions happens with the class from enterprise library January 2006. Following is my code: DataTable dt = new DataTable();                   DataColumn dcol = new DataColumn("Col1", typeof(int));                   dt.Columns.Add(dcol);                   DataRow dr;                   dr = dt.NewRow();                   dr["Col1"] = 1;                   dt.Rows.Add(dr);                   SqlParameter parameter = new SqlParameter("@MenuRights", SqlDbType.Structured);                   parameter.Value = dt;                   DataTable dtbl = ExecuteDatabaseQuery.Reference.ExecuteQuery_DataTable(ConAdmin, "teststorepro", "teststorepro",                         ProjectConstants.QueryType.StoredProc, null, true, null,                         parameter); When the sqlcommand is made and passed for executing, it throws an error "Failed to convert parameter value to IEnumerable". Following is the code from enterprise library: Database db = (Database)CreateConnection(ConnectionName);                         if (WriteInfoInLogFile == true && WriteToLogs == true)                         {                               CLogger.Reference.sLogInfo(ConnectionName, OptionName, oQuery, TypeOfQuery, CLogger.EStatus.StartProcess, LogMsg, CLogger.MsgType.Information, SQLParams);                         }       &n

    S 1 Reply Last reply
    0
    • S sanjubaba

      Hi,    I am trying to pass a datatable as a parameter to a stored procedure. my sql server is 2008. Also my database transactions happens with the class from enterprise library January 2006. Following is my code: DataTable dt = new DataTable();                   DataColumn dcol = new DataColumn("Col1", typeof(int));                   dt.Columns.Add(dcol);                   DataRow dr;                   dr = dt.NewRow();                   dr["Col1"] = 1;                   dt.Rows.Add(dr);                   SqlParameter parameter = new SqlParameter("@MenuRights", SqlDbType.Structured);                   parameter.Value = dt;                   DataTable dtbl = ExecuteDatabaseQuery.Reference.ExecuteQuery_DataTable(ConAdmin, "teststorepro", "teststorepro",                         ProjectConstants.QueryType.StoredProc, null, true, null,                         parameter); When the sqlcommand is made and passed for executing, it throws an error "Failed to convert parameter value to IEnumerable". Following is the code from enterprise library: Database db = (Database)CreateConnection(ConnectionName);                         if (WriteInfoInLogFile == true && WriteToLogs == true)                         {                               CLogger.Reference.sLogInfo(ConnectionName, OptionName, oQuery, TypeOfQuery, CLogger.EStatus.StartProcess, LogMsg, CLogger.MsgType.Information, SQLParams);                         }       &n

      S Offline
      S Offline
      sanjubaba
      wrote on last edited by
      #2

      any solution thanks

      Sandeep Kumbhar

      modified on Wednesday, September 16, 2009 12:00 AM

      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