【求解】连续输入几十次错误的数据后提示“未知的错误”,再输入正确数据的都显示“未知的错误”
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.OleDb;using System.Data.SqlClient;namespace WindowsFormsApplication1{ public partial class IMEI查找工具 : Form { public IMEI查找工具() { InitializeComponent(); } private const int WM_LBUTTONDOWN = 0x201; private const int WM_LBUTTONUP = 0x202; private void TextEnable(bool a_Enable) { textBox1.Enabled = a_Enable; if (a_Enable) { textBox1.Focus(); textBox1.SelectAll(); textBox1.Text = ""; } } private void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { try { string strpath; strpath = textBox2.Text; OleDbConnection myConn = new OleDbConnection(); myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + strpath; myConn.Open(); label3.Text = "表" + strpath + "连接成功!"; label3.BackColor = Color.LawnGreen; textBox2.Enabled = false; } catch (Exception ex) { label3.Text = ( ex.Message + "\n FAIL"); label3.BackColor = Color.Red; } } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox1_KeyPress(object sender, KeyPressEventArgs ex) { if (ex.KeyChar == 13) { this.button2_Click(sender, ex); } } private void button2_Click(object sender, EventArgs e) { try { string a; string strsql; string IMEI; a = textBox1.Text; int count; string strpath; strpath = textBox2.Text; OleDbConnection myConn = new OleDbConnection(); myConn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + strpath; myConn.Open(); strsql = "select * from ZTE_MBC_BARCODE_IMEI where IMEI='" + a + "'"; OleDbCommand mycmd = myConn.CreateCommand(); mycmd.CommandText = strsql; OleDbDataReader mydr = mycmd.ExecuteReader(); mydr.Read(); count = 0; while (count == 0) { count += 1; IMEI = mydr["IMEI"].ToString(); label2.Text = "IMEI号:" + IMEI + ",\n PASS"; label2.BackColor = Color.LawnGreen; break; } TextEnable(true); textBox2.Enabled = false; myConn.Close(); } catch (Exception ex) { label2.Text=("IMEI:" + textBox1.Text +","+"\n"+ ex.Message+"\n FAIL"); label2.BackColor = Color.Red; textBox1.Focus(); textBox1.SelectAll(); } } private void textBox2_TextChanged(object sender, EventArgs e) { } }}