此代码实际上是用dataset方法编写的。 它工作得很好。但是我想把它改成datareader方法。
public DataSet SelectTopic(LessionPlanBEL bellp)
{
DataSet ds = new DataSet();
try
{
con.Open();
string query = "Select * from lessiontopic where subject=@subject ";
SqlDataAdapter da = new SqlDataAdapter(query, con);
da.SelectCommand.Parameters.Add("@subject", SqlDbType.Int).Value = bellp.subject;
da.Fill(ds);
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
return ds;
}
答案 0 :(得分:1)
试试这个
public DataSet SelectTopic(LessionPlanBEL bellp)
{
SqlDataReader dr = new SqlDataReader();
SqlCommand cmd;
try
{
con.Open();
cmd =new SqlCommand( "Select * from lessiontopic where subject=@subject ",conn);
cmd.Parameters.AddWithValue("@subject", bellp.subject.ToString());
dr=cmd.ExecuteReader();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}