当前位置: 代码迷 >> .NET相关 >> 求C#好手
  详细解决方案

求C#好手

热度:401   发布时间:2016-04-24 03:03:26.0
求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();
  相关解决方案