首页上一页 1 下一页尾页 3 条记录 1/1页
SqlDataReader 的用法
发表在ASP.NET图书答疑
2010-03-24
是否精华
是
否
版块置顶:
是
否
DAL: public SqlDataReader GetAdminNameAndPassword()
{
SqlConnection conn = connectionManger.GetConnectionStr();
SqlDataReader dr = null;
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select AdminName,AdminPassword from [dbo].[T_Admin]", conn);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dr.Read();
}
catch (SqlException se)
{
throw se;
}
finally
{
//dr.Dispose();
//dr.Close();
if (conn.State != System.Data.ConnectionState.Closed)
{
conn.Close();
}
conn.Dispose();
}
return dr;
}
BLL:.......省略
界面后台代码: protected void GetAdminNameAndPassword()
{
SqlDataReader dr = new BBSBBL.T_AdminInfo().GetAdminNameAndPassword();
dr.Read();
this.txtAdminName.Text = dr.GetString(0);
this.txtAdminPassword.Text = dr.GetString(1);
}
错误提示:阅读器关闭时尝试调用 Read 无效
行 24: {
行 25: SqlDataReader dr = new BBSBBL.T_AdminInfo().GetAdminNameAndPassword();
行 26: dr.Read();-------此行代码是红色的
行 27: this.txtAdminName.Text = dr.GetString(0);
行 28: this.txtAdminPassword.Text = dr.GetString(1);
{
SqlConnection conn = connectionManger.GetConnectionStr();
SqlDataReader dr = null;
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select AdminName,AdminPassword from [dbo].[T_Admin]", conn);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dr.Read();
}
catch (SqlException se)
{
throw se;
}
finally
{
//dr.Dispose();
//dr.Close();
if (conn.State != System.Data.ConnectionState.Closed)
{
conn.Close();
}
conn.Dispose();
}
return dr;
}
BLL:.......省略
界面后台代码: protected void GetAdminNameAndPassword()
{
SqlDataReader dr = new BBSBBL.T_AdminInfo().GetAdminNameAndPassword();
dr.Read();
this.txtAdminName.Text = dr.GetString(0);
this.txtAdminPassword.Text = dr.GetString(1);
}
错误提示:阅读器关闭时尝试调用 Read 无效
行 24: {
行 25: SqlDataReader dr = new BBSBBL.T_AdminInfo().GetAdminNameAndPassword();
行 26: dr.Read();-------此行代码是红色的
行 27: this.txtAdminName.Text = dr.GetString(0);
行 28: this.txtAdminPassword.Text = dr.GetString(1);