Witam,
przy wywołaniu takiej funkcji:
public SqlDataReader getAllEntries()
{
SqlConnection DBConn = new SqlConnection();
DBConn.ConnectionString = conString;
string sqlProcedure = "GetAllEntries";
SqlCommand sqlCmd = new SqlCommand(sqlProcedure, DBConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
DBConn.Open();
SqlDataReader sdr = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
DBConn.Close();
return sdr;
}
otrzymuję błąd
Invalid attempt to call FieldCount when reader is closed
Jestem nowy jeśli chodzi o technologię ASP.NET i niezbyt wiem czym to jest spowodowane, wydaje mi się że wszystko powinno być w porządku ale jednak nie jest, np jeśli zwracałbym dataset to wszystko jest oki. Jaki bład popełniam przy korzystaniu sqldatareader'a?
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
string sqlProcedure = "GetAllEntries";
SqlCommand sqlCmd = new SqlCommand(sqlProcedure, DBConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
sda.SelectCommand = sqlCmd;
sda.Fill(ds);
return ds;
Tutaj wszystko jest oki.
Prosiłbym o pomoc, z góry dzięki.