J
Jon Haakon Ariansen
Hi,
I realize that it's not possible to get the rowcount from SqlDataReader, but
if you have a stored procedure where you return @@ROWCOUNT it should be
possible to get the rowcount through the returnvalue parameter to
sqldatareader, shouldn't it???
Here is an example:
SqlDataReader dr = null;
SqlConnection sc = new SqlConnection(_conn);
SqlCommand _cmd = new SqlCommand("spShowTeamDetails", sc);
_cmd.CommandTimeout = 30;
_cmd.CommandType = CommandType.StoredProcedure;
SqlParameter _paramSocietyID = new SqlParameter("@SocietyID",
SqlDbType.UniqueIdentifier);
_paramSocietyID.Value = SocietyID;
_cmd.Parameters.Add(_paramSocietyID);
SqlParameter _rowCount = new SqlParameter("@ReturnValue", SqlDbType.Int);
_rowCount.Direction = ParameterDirection.ReturnValue;
_cmd.Parameters.Add(_rowCount);
sc.Open();
dr = _cmd.ExecuteReader();
if(Convert.ToInt32(_rowCount.Value) ==1) //_rowCount.Value returns null
even though it returns one record in query analyser
{
while (dr.Read())
{
..........
}
}
else
throw new Exception("Unique society not found.")
In advance - thanks for your help
I realize that it's not possible to get the rowcount from SqlDataReader, but
if you have a stored procedure where you return @@ROWCOUNT it should be
possible to get the rowcount through the returnvalue parameter to
sqldatareader, shouldn't it???
Here is an example:
SqlDataReader dr = null;
SqlConnection sc = new SqlConnection(_conn);
SqlCommand _cmd = new SqlCommand("spShowTeamDetails", sc);
_cmd.CommandTimeout = 30;
_cmd.CommandType = CommandType.StoredProcedure;
SqlParameter _paramSocietyID = new SqlParameter("@SocietyID",
SqlDbType.UniqueIdentifier);
_paramSocietyID.Value = SocietyID;
_cmd.Parameters.Add(_paramSocietyID);
SqlParameter _rowCount = new SqlParameter("@ReturnValue", SqlDbType.Int);
_rowCount.Direction = ParameterDirection.ReturnValue;
_cmd.Parameters.Add(_rowCount);
sc.Open();
dr = _cmd.ExecuteReader();
if(Convert.ToInt32(_rowCount.Value) ==1) //_rowCount.Value returns null
even though it returns one record in query analyser
{
while (dr.Read())
{
..........
}
}
else
throw new Exception("Unique society not found.")
In advance - thanks for your help