Mr. Thekotik

Mr. Thekotik

  • NA
  • 32
  • 3.2k

Multi-criteria search Functionality to your Access application ?#

May 27 2021 1:32 PM
Error:
 
System. ArgumentException: "This list cannot be cleared."
 
Code:
  1. private void button3_Click(object sender, EventArgs e)  
  2. {  
  3. if ((textBox2.Text != "") ||  
  4. (textBox3.Text != "") ||  
  5. (textBox4.Text != "") ||  
  6. (textBox5.Text != "") ||  
  7. (textBox10.Text != "") ||  
  8. (textBox8.Text != ""))  
  9. {  
  10. if (radioButton1.Checked == false & radioButton2.Checked == false) { radioButton1.Checked = true; }  
  11. dataGridView1.Rows.Clear();  
  12. string type = "";  
  13. string name = "";  
  14. string weight = "";  
  15. string company = "";  
  16. string client = "";  
  17. string price = "";  
  18. string log = "";  
  19. int y = 0;  
  20. if (radioButton2.Checked == true) { log = "OR "; }  
  21. if (radioButton1.Checked == true) { log = "AND "; }  
  22. if (textBox2.Text != "")  
  23. {  
  24. type = "??? = '" + textBox2.Text + "'"; y = 1;  
  25. }  
  26. if (textBox3.Text != "")  
  27. {  
  28. if (y == 1) { name = "" + log + "???????????? = '" + textBox4.Text + "'"; } else { name = "???????????? = '" + textBox4.Text + "'"; y = 1; }  
  29. }  
  30. if (textBox3.Text != "")  
  31. {  
  32. if (y == 1) { weight = "" + log + "??? = " + textBox4.Text + ""; } else { weight = "??? = " + textBox4.Text + ""; y = 1; }  
  33. }  
  34. if (textBox5.Text != "")  
  35. {  
  36. if (y == 1) { company = "" + log + "????? = '" + textBox5.Text + "'"; } else { company = "????? = '" + textBox5.Text + "'"; y = 1; }  
  37. }  
  38. if (textBox10.Text != "")  
  39. {  
  40. if (y == 1) { client = "" + log + "?????????? = '" + textBox10.Text + "'"; } else { client = "?????????? = '" + textBox10.Text + "'"; y = 1; }  
  41. }  
  42. if (textBox8.Text != "")  
  43. {  
  44. if (y == 1) { price = "" + log + "???? = " + textBox8.Text + ""; } else { price = "???? = " + textBox8.Text + ""; y = 1; }  
  45. }  
  46. string query = "SELECT ???, ????????????, ???, ?????, ??????????, ???? FROM ??????? WHERE " + type + name + weight + company + client + price + "";  
  47. Form2 form2 = new Form2();  
  48. OleDbCommand command = new OleDbCommand(query, form2.Connection);  
  49. OleDbDataReader reader = command.ExecuteReader();  
  50. while (reader.Read())  
  51. {  
  52. dataGridView1.Rows.Add(  
  53. reader[0].ToString(),  
  54. reader[1].ToString(),  
  55. reader[2].ToString(),  
  56. reader[3].ToString(),  
  57. reader[4].ToString(),  
  58. reader[5].ToString());  
  59. }  
  60. reader.Close();  
  61. }  
  62. else  
  63. {  
  64. MessageBox.Show("?? ?????? ?? ?????!");  
  65. }  
  66. }  

Answers (1)