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;
}
{
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;
}
解决方案 »
- 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载..... ???
- WinForms开发的斗地主,资源销毁问题 (50分)
- 请找出以下代码哪些地方有问错,请修改,谢谢。
- 请教一个被其他页面共用的.aspx文件的问题~~~
- :[Microsoft][ODBC 驱动程序管理器] 驱动程序的 SQLSetConnectAttr 失败? 怎么回事啊
- js写的日历控件为什么在asp.net页面不好使?
- 大哥,小弟在线恭候您呐。。。
- 为何JAVASCRIPT一打开页面调用模态对话框错误提示说对话框不支持属性或方法
- 登录验证码 ashx文件中获取不到session值
- 一个小问题,谢谢
- 急在线等,这个问题是什么情况解决
- C#写的ACTIVEX控件,IE 中皮肤显示问题
using(SqlDataReader rs = con1.recordset(CommandBehavior.CloseConnection);)
{
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();
....
}