当前位置: 代码迷 >> ASP.NET >> 阅读器封锁时尝试调用 MetaData 无效
  详细解决方案

阅读器封锁时尝试调用 MetaData 无效

热度:9834   发布时间:2013-02-25 00:00:00.0
阅读器关闭时尝试调用 MetaData 无效。
代码如下:
 protected void TextBox2_TextChanged(object sender, EventArgs e)
  {  
  foreach (GridViewRow gvr in this.GridView1.Rows)
  {
  TextBox num = (TextBox)gvr.FindControl("TextBox2");
  int count = Int32.Parse(num.Text);
  string bookname = gvr.Cells[0].Text;
  SqlConnection con = db.GetConnection();
  con.Open();
  SqlCommand cmd =new SqlCommand ("select stock from tb_BookInfo where BookName='"+bookname+"'",con);
  SqlDataReader sdr = cmd.ExecuteReader ();
  sdr.Read();
  int re = Convert.ToInt32(sdr[0].ToString());
  con.Close();
  if (re < count)
  {
  Response.Write(comm .MessageBox ("库存不足!","ShopCar.aspx"));
  Response.End();
  }
  }

  }

------解决方案--------------------------------------------------------
把con.Close();
移到foreach外面。
都关闭了还怎么读数据啊。
------解决方案--------------------------------------------------------
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvr in this.GridView1.Rows)
{
TextBox num = (TextBox)gvr.FindControl("TextBox2");
int count = Int32.Parse(num.Text);
string bookname = gvr.Cells[0].Text;
SqlConnection con = db.GetConnection();
con.Open();
SqlCommand cmd =new SqlCommand ("select stock from tb_BookInfo where BookName='"+bookname+"'",con);
SqlDataReader sdr = cmd.ExecuteReader ();
sdr.Read();
int re = Convert.ToInt32(sdr[0].ToString());
if (re < count)
{
Response.Write(comm .MessageBox ("库存不足!","ShopCar.aspx"));
Response.End();
}
}
con.Close();
}
  相关解决方案