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. Database & SysAdmin
  3. Database
  4. Read Output parameter with ExecuteReader in DAAB

Read Output parameter with ExecuteReader in DAAB

Scheduled Pinned Locked Moved Database
databasehelpquestion
2 Posts 2 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.
  • M Offline
    M Offline
    Meysam Mahfouzi
    wrote on last edited by
    #1

    I'm using DAAB (Enterprise Library) for accessing database. My problem is I can't read output parameters when using DataReader. That is I can only read stored procedure's output parameter only when I use ExecuteNonQuery or ExecuteScalar functions. When I use ExecuteReader function, the output parameter is 0. Do you know how I can read output parameter when using ExecuteReader function? here is a sample code:

    var db = new SqlDatabase(ConnectionString);
    string sqlCommand = "ReadItems";
    DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
    db.AddInParameter(dbCommand, "@Count", SqlDbType.Int, count);
    db.AddOutParameter(dbCommand, "@Total", SqlDbType.Int, sizeof(Int32));
    var reader = db.ExecuteReader(dbCommand);
    while (reader.Read())
    {
    // read items
    }
    int total = Convert.ToInt32(dbCommand.Parameters["@Total"].Value); // total is 0

    A 1 Reply Last reply
    0
    • M Meysam Mahfouzi

      I'm using DAAB (Enterprise Library) for accessing database. My problem is I can't read output parameters when using DataReader. That is I can only read stored procedure's output parameter only when I use ExecuteNonQuery or ExecuteScalar functions. When I use ExecuteReader function, the output parameter is 0. Do you know how I can read output parameter when using ExecuteReader function? here is a sample code:

      var db = new SqlDatabase(ConnectionString);
      string sqlCommand = "ReadItems";
      DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
      db.AddInParameter(dbCommand, "@Count", SqlDbType.Int, count);
      db.AddOutParameter(dbCommand, "@Total", SqlDbType.Int, sizeof(Int32));
      var reader = db.ExecuteReader(dbCommand);
      while (reader.Read())
      {
      // read items
      }
      int total = Convert.ToInt32(dbCommand.Parameters["@Total"].Value); // total is 0

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      You need to close the reader before you can get the output parameters. No idea why, it has always been this way.

      Bob Ashfield Consultants Ltd

      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