i have 2 stored procedures: a delete and a select. the delete sp returns the rowcount properly. the select returns null. the code for both sp's is extremely simple and extremely similar. when i execute the select sp in server management studio the rowcount shows a 1 as expected. but the calling method gets null.
SP Code
ALTER
PROCEDURE [dbo].[RetrieveEmployeeKeyFromAssignmentTable]@.assignmentPrimaryKey
int,@.rowCount
intOUTPUTAS
BEGIN
SETNOCOUNTON;SELECT employeePrimaryKeyFROM assignmentTableWHERE primaryKey= @.assignmentPrimaryKey;SET @.rowCount=@.@.RowCount;END
c# code
SqlConnection
conn = GetOpenSqlConnection();if (conn ==null) returntrue;SqlDataReader reader =null;SqlParameter p1 =newSqlParameter(); SqlParameter p2 =newSqlParameter();try{SqlCommand command =newSqlCommand();command.CommandText =
"RetrieveEmployeeKeyFromAssignmentTable";command.CommandType =
CommandType.StoredProcedure;command.Connection = conn;
p1.ParameterName =
"@.assignmentPrimaryKey";p1.Value = assignmentPrimaryKey;
p2.ParameterName =
"@.rowCount";p2.Direction =
ParameterDirection.Output;p2.Value = 0;
command.Parameters.Add(p1); command.Parameters.Add(p2);reader = command.ExecuteReader();
if (p2.Value ==null)//always trueany suggestions would be appreciated.
thanks. matt
also, reader.HasRows is true.
matt
|||Hello,
first, I was suspicious of your code that you assigned the value of output parameter p2.value=0.
but it was O.K., and I was wrong , I tested with query analyzer.
I looked carefully in your code, find that you called with ExecuteReader ==> it is connected data object.
you have to close the Reader object before you try to get Output or else paremeter values.
verified with internet search...
|||
EXCELLENT.
thank you very much.
matt
No comments:
Post a Comment