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. problem with output parameter

problem with output parameter

Scheduled Pinned Locked Moved Database
questioncsharpdatabasehelp
4 Posts 3 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
    Mr Kode
    wrote on last edited by
    #1

    i have stored procedure with two parameters as follows: create procedure checkCompatability ( @compatility varchar output, @award_num int ) AS SET NOCOUNT OFF; IF EXISTS (SELECT Award_num from table1 where award_num=@award_num) begin set @compatability='Y' print @compatability end else set @compatability='N' print @compatability GO in C# parameters: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.Connection.Open(); checkDone.CommandType = CommandType.StoredProcedure; checkDone.CommandText = "checkCompatability"; SqlParameter comp = new SqlParameter("@compatability", SqlDbType.VarChar); string S = comp.Value.ToString();\\null reference exception occours here lblresult.Text = S.ToString(); comp.Direction = ParameterDirection.Output; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Input; int awN = int.Parse(comboAwardNum.Text); complete.Value =(int) awN; lblresult.Text = comp.Value.ToString(); checkDone.Parameters.Add(comp); checkDone.Parameters.Add(complete); checkDone.ExecuteNonQuery(); checkDone.Connection.Close(); what is the problem with that code?

    M 1 Reply Last reply
    0
    • M Mr Kode

      i have stored procedure with two parameters as follows: create procedure checkCompatability ( @compatility varchar output, @award_num int ) AS SET NOCOUNT OFF; IF EXISTS (SELECT Award_num from table1 where award_num=@award_num) begin set @compatability='Y' print @compatability end else set @compatability='N' print @compatability GO in C# parameters: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.Connection.Open(); checkDone.CommandType = CommandType.StoredProcedure; checkDone.CommandText = "checkCompatability"; SqlParameter comp = new SqlParameter("@compatability", SqlDbType.VarChar); string S = comp.Value.ToString();\\null reference exception occours here lblresult.Text = S.ToString(); comp.Direction = ParameterDirection.Output; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Input; int awN = int.Parse(comboAwardNum.Text); complete.Value =(int) awN; lblresult.Text = comp.Value.ToString(); checkDone.Parameters.Add(comp); checkDone.Parameters.Add(complete); checkDone.ExecuteNonQuery(); checkDone.Connection.Close(); what is the problem with that code?

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      You cannot retrieve the value of output parameters until after you have executed the stored procedure and retrieved all the results (if any). (The latter is a SQL Server limitation: when in 'firehose' mode it doesn't return the output parameter values until after the entire result data stream has been sent.)

      DoEvents: Generating unexpected recursion since 1991

      M 1 Reply Last reply
      0
      • M Mike Dimmick

        You cannot retrieve the value of output parameters until after you have executed the stored procedure and retrieved all the results (if any). (The latter is a SQL Server limitation: when in 'firehose' mode it doesn't return the output parameter values until after the entire result data stream has been sent.)

        DoEvents: Generating unexpected recursion since 1991

        M Offline
        M Offline
        Mr Kode
        wrote on last edited by
        #3

        do you mean that i should execute the command before initailize the parameters?

        A 1 Reply Last reply
        0
        • M Mr Kode

          do you mean that i should execute the command before initailize the parameters?

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

          No, set the parameters, execute the proc and THEN get the output value. Also, stop double posting - this was in the C# forum as well. :mad:

          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