本人在修改数据库后,绑定datagrid,使得datagrid刷新,有下面的代码,请问为何有时候行,有时候又不行了?其中materials是DataGrid,connstr()用来判断conn.open,如果open什么也不做,如果close就open.而conn是在打开数据库连接时在web.config中设置的,即
public static string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
public static SqlConnection conn=new SqlConnection(ConnString);

而clmc是在html中DataGrid属性中添加
<asp:TemplateColumn>
<ItemTemplate>
<a target="MainFrame" href="qtclxx.aspx?clmc=<%# DataBinder.Eval(Container.DataItem,"材料名称")%>">
<asp:CheckBox id="CheckBox1"  AutoPostBack="True" Checked="False" runat="server" ></asp:CheckBox>
</a>
</ItemTemplate>
</asp:TemplateColumn>
在控件中修改数据库后调用 this.OpenDB1();
private void OpenDB1()
{
  try
  {
    try
    {
      string clmcstr=Request.QueryString["clmc"].ToString();
      string clmc1=clmcstr.Trim();
      string sql="select * from 材料信息全 where 材料名称='"+clmc1+"'";
   connstr();
      SqlCommand cmd=new SqlCommand(sql,conn);
   SqlDataReader dr=cmd.ExecuteReader();
   if(dr.Read())
   {
    dr.Close();
     string sql1="select * from 材料信息全 where 材料名称='"+dr["材料名称"].ToString()+"'";
   connstr();
   SqlDataAdapter da=new SqlDataAdapter(sql1,conn);
   DataSet ds=new DataSet();
   da.Fill(ds,"A");
   materials.DataSource=ds.Tables["A"];
   materials.DataBind();
   conn.Close();
   }
   else
   {
   dr.Close();
   conn.Close();
   Response.Write("系统错误!");
   Response.End();
   }
         }
        catch(Exception)
       {
   string sql="select * from 材料信息全";
   connstr();
   SqlDataAdapter da=new SqlDataAdapter(sql,conn);
   DataSet ds=new DataSet();
   da.Fill(ds,"A");
   materials.DataSource=ds.Tables["A"];
   materials.DataBind();
   conn.Close();
   }
         }
         catch(Exception)
        {
   Response.Write("登录超时!");
   string sql="select * from 材料信息全";
   connstr();
   SqlDataAdapter da=new SqlDataAdapter(sql,conn);
   DataSet ds=new DataSet();
   da.Fill(ds,"A");
   materials.DataSource=ds.Tables["A"];
   materials.DataBind();
   conn.Close();
   Response.End();
         }
   }


希望大侠帮忙,为何有时行有时不行呢?