查询问题 各位帮帮忙 先谢谢啦
功能是在Form中的文本框中输入内容,点击查询按钮,把符合的内容显示在DataGrid中。上述功能实现只能查询一次,不会出现问题,当再重新输入内容再次查询时出现错误,不能实现查询了,问题在哪里?
请指教!谢谢了!
代码如下:
private void Form1_Load(object sender, System.EventArgs e)
{
string Connstr,SelectCmd;
Connstr= "Server=(local);Database=tester1;Trusted_Connection=SSPI ";
SelectCmd= "select* From EquipmentInformation ORDER by id desc ";
SqlConnection Conn;
SqlDataAdapter myAdapter;
DataSet myDataSet=new DataSet ();
Conn=new SqlConnection (Connstr);
myAdapter=new SqlDataAdapter (SelectCmd,Conn);
myAdapter.Fill(myDataSet, "设备信息 ");
dataGrid1.DataSource=myDataSet;
dataGrid1.DataMember= "设备信息 ";
cbo1.Text = dataGrid1[0, 1].ToString();
textBox2.Text = dataGrid1[0,2 ].ToString();
textBox3.Text = dataGrid1[0,3 ].ToString();
cbo2.Text = dataGrid1[0,4 ].ToString();
textBox5.Text = dataGrid1[0,5 ].ToString();
textBox6.Text = dataGrid1[0,6 ].ToString();
textBox7.Text = dataGrid1[0,7 ].ToString();
}
private int CheckInt(string str)
{
try
{
return int.Parse (str);
}
catch
{
return 0;
}
}
private void btn8_Click(object sender, System.EventArgs e)
{
string Connstr,SelectCmd;
Connstr= "Server=(local);Database=tester1;Trusted_Connection=SSPI ";
SelectCmd= "select* From EquipmentInformation Where SubstationName= ' "+cbo1.Text + " 'or EquipmentID= ' "+CheckInt(textBox2.Text)+ " 'or OperationID= ' "+CheckInt(textBox5.Text)+ " ' ORDER by id desc ";;
SqlConnection Conn;
SqlDataAdapter myAdapter;
DataSet myDataSet=new DataSet ();
Conn=new SqlConnection (Connstr);
myAdapter=new SqlDataAdapter (SelectCmd,Conn);
myAdapter.Fill(myDataSet, "设备信息 ");
cbo1.DataSource =myDataSet;
cbo1.DisplayMember = "设备信息.SubstationName ";
cbo2.DataSource =myDataSet;
cbo2.DisplayMember = "设备信息.TesterName ";
textBox2.DataBindings.Add ( "text ",myDataSet, "设备信息.EquipmentID ");
textBox3.DataBindings.Add ( "text ",myDataSet, "设备信息.VoltageGrade ");
textBox5.DataBindings.Add ( "text ",myDataSet, "设备信息.OperationID ");
textBox6.DataBindings.Add ( "text ",myDataSet, "设备信息.Modle ");
textBox7.DataBindings.Add ( "text ",myDataSet, "设备信息.Data ");
dataGrid1.DataSource=myDataSet;
dataGrid1.DataMember= "设备信息 ";
}
错误如下:
未处理的“
小弟我在使用ICSharpCode.SharpZipLib进行目录压缩后,再解压缩是提示这个异常