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