G
Guest
I am encountering the following problem with a call to a stored procedure
from C# code.
The stored procedure looks like this:
ALTER PROCEDURE sproc
@id1 int,
@id2 int,
@trans_date datetime,
@flag1 bit output,
@result int Output
AS
..
..
..
Set @flag1 = (SELECT flag From MyTable
Where id = @id2)
-- A record is found and debugger shows @flag1 has a value
..
..
..
Return 0
The C# code:
sqlCmdData.CommandText = "sproc";
sqlCmdData.Parameters.Clear();
sqlCmdData.Parameters.AddWithValue("@id1", _id1);
sqlCmdData.Parameters.AddWithValue("@id2", _id2);
sqlCmdData.Parameters.AddWithValue("@trans_date", DateTime.Now);
SqlParameter sqlParmFlag = new SqlParameter("@flag1", SqlDbType.Bit);
sqlParmFlag.Direction = ParameterDirection.Output;
sqlCmdData.Parameters.Add(sqlParmFlag);
SqlParameter sqlParmResult = new SqlParameter("@result", SqlDbType.Int);
sqlParmResult.Direction = ParameterDirection.Output;
sqlCmdData.Parameters.Add(sqlParmResult);
SqlDataReader dr = sqlCmdData.ExecuteReader();
int _status = Convert.ToInt32(sqlParmResult.Value); // This works OK
bool flag = (bool)sqlParmFlag.Value; // sqlParmFlag.Value is always NULL
This throws a NULL exception.
Any ideas on what may be happening here?
I would appreciate any help.
Thanks,
Eagle
from C# code.
The stored procedure looks like this:
ALTER PROCEDURE sproc
@id1 int,
@id2 int,
@trans_date datetime,
@flag1 bit output,
@result int Output
AS
..
..
..
Set @flag1 = (SELECT flag From MyTable
Where id = @id2)
-- A record is found and debugger shows @flag1 has a value
..
..
..
Return 0
The C# code:
sqlCmdData.CommandText = "sproc";
sqlCmdData.Parameters.Clear();
sqlCmdData.Parameters.AddWithValue("@id1", _id1);
sqlCmdData.Parameters.AddWithValue("@id2", _id2);
sqlCmdData.Parameters.AddWithValue("@trans_date", DateTime.Now);
SqlParameter sqlParmFlag = new SqlParameter("@flag1", SqlDbType.Bit);
sqlParmFlag.Direction = ParameterDirection.Output;
sqlCmdData.Parameters.Add(sqlParmFlag);
SqlParameter sqlParmResult = new SqlParameter("@result", SqlDbType.Int);
sqlParmResult.Direction = ParameterDirection.Output;
sqlCmdData.Parameters.Add(sqlParmResult);
SqlDataReader dr = sqlCmdData.ExecuteReader();
int _status = Convert.ToInt32(sqlParmResult.Value); // This works OK
bool flag = (bool)sqlParmFlag.Value; // sqlParmFlag.Value is always NULL
This throws a NULL exception.
Any ideas on what may be happening here?
I would appreciate any help.
Thanks,
Eagle