textBox输入逐渐变得很慢的原因????
现象:在EXTBOX中输入关键字,可以在列表(datagridview)出现资料,但输入十几次后,输入开始变得很慢。要重启软件,速度才变得正常,但输入10几次后,又变得很慢了。这是什么呢?请指点,,谢谢。。
是没释放内存??,没关闭对象??
c# 相关代码
private void textBox8_TextChanged(object sender, EventArgs e)//产品检索
{
try
{
string s = this.textBox8.Text.ToString();
string sqlstr = "materiel_smalluser_select_forpart '" + textBox8.Text + "'";
this.materielshow.DataSource = SQLclass.getds(sqlstr, "tba").Tables[0];
this.materielshow.DefaultCellStyle.ForeColor = Color.Black;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "提示");
}
}
public DataSet getds(string strsql, string tableName)
{
getcon();
SqlDataAdapter sdr = new SqlDataAdapter(strsql, My_con);
DataSet ds = new DataSet();
sdr.Fill(ds, tableName);
con_close();
return ds;
}
public static SqlConnection getcon()
{
My_con = new SqlConnection(strcon);
My_con.Open();
return My_con;
}
public void con_close()
{
if (My_con.State == ConnectionState.Open)
{
My_con.Close();
My_con.Dispose();
}
}