日期:2014-05-20  浏览次数:20790 次

求C#高手
  {
           string sql;
           if (comboBox1.SelectedIndex == 0)
           {
               MessageBox.Show("请选择查询类型");
               comboBox1.Focus();
               return;
           }
           else
           {
               switch (comboBox1.SelectedIndex)
               {
                   case 1:
                       sql = string.Format("select CustomerId,CustomerName,Tel,CustomerADR from customer where CustomerId= '{0}'", this.textBox1.Text);
                       Program.command = new OleDbCommand(sql, Program.objConnection);
                       //  Program.command.ExecuteNonQuery();
                       break;
                   case 2:
                       sql = string.Format("select CustomerId,CustomerName, Tel,CustomerADR from customer where CustomerName='{0}'", this.textBox1.Text);
                       Program.command = new OleDbCommand(sql, Program.objConnection);
                       //Program.command.ExecuteNonQuery();
                       break;
                   case 3:
                       sql = string.Format("select CustomerId,CustomerName, Tel,CustomerADR from customer where Tel='{0}'", this.textBox1.Text);
                       Program.command = new OleDbCommand(sql, Program.objConnection);
                       //Program.command.ExecuteNonQuery();
                       break;
                   case 4:
                       sql = string.Format("select CustomerId,CustomerName,CustomerADR ,Tel from customer where CustomerADR='{0}'", this.textBox1.Text);
                       Program.command = new OleDbCommand(sql, Program.objConnection);
                       //  Program.command.ExecuteNonQuery();
                       break;
               }
           }
           OleDbDataReader reader = Program.command.ExecuteReader();
        // listView1.Clear();
           if (reader.HasRows)
           {
               while (reader.Read())
               {
                   ListViewItem item = new ListViewItem();
                   item.Text = reader["customerID"].ToString();