连接未关闭。连接的当前状态为已打开。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ysconn con1 = new ysconn();
con1.sqlString = "select * from ys_info where info_id='" + Request.QueryString["info_id"] + "'";
SqlDataReader rs = con1.recordset();
int m, j;
string A;
string[] tmpA = new string[1];
if (rs.HasRows)
{
rs.Read();
info_id.Text = rs["info_id"].ToString();
}
rs.Close();
con1.Close();
con1.sqlString = "select x_yslx from ys_xq where info_id='" + Request.QueryString["info_id"] + "' group by x_yslx";
rs = con1.recordset();
while (rs.Read())
{
for (m = 0; m < this.yslx.Items.Count; m++)
{
if (rs[0].ToString() == this.yslx.Items[m].Value)
{
this.yslx.Items[m].Selected = true;
this.yslx.Items[m].Enabled = false;
}
}
}
rs.Close();
con1.Close();
con1.CloseConn();
}
else
{
int m;
for (m = 0; m < this.yslx.Items.Count; m++)
{
if (this.yslx.Items[m].Selected == true)
{
ysconn con1 = new ysconn();
con1.sqlString = "select x_yslx from ys_xq where info_id='" + Request.QueryString["info_id"] + "' group by x_yslx";
SqlDataReader rs = con1.recordset();
rs = con1.recordset();
while (rs.Read())
{
}
rs.Dispose();
con1.CloseConn();
}
}
}
}
始终提示 ysconn.cs 行: 53 错误: 连接未关闭。连接的当前状态为已打开。
public SqlDataReader recordset()
{
SqlCommand mycom = new SqlCommand(_sqlString, mycon);
mycon.Open(); //53行
SqlDataReader reader = mycom.ExecuteReader();
return reader;
}