Ghali Mongi

Ghali Mongi

  • NA
  • 5
  • 990

Problem with Search DataGridView by using ComboBox and Text

Apr 17 2020 6:01 AM
Good morning all,

I try to affect a filter / search on datagridview by a combobox and textbox but when I type the first letter (s) on textbox an error message is displayed:

System.Data.SqlClient.SqlException*: 'Syntaxe incorrect vers 's%'.'

here is my code:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.Configuration;  
  11. using System.Data.SqlClient;  
  12.   
  13. namespace TESTSEARCH  
  14. {  
  15. public partial class FormFind : Form  
  16. {  
  17. public FormFind()  
  18. {  
  19. InitializeComponent();  
  20. }  
  21. private void FormFind_Load(object sender, EventArgs e)  
  22. {  
  23. }  
  24. private void textBox1_TextChanged(object sender, EventArgs e)  
  25. {  
  26. string constring = ConfigurationManager.ConnectionStrings["TESTDEMO.Properties.Settings.connect"].ConnectionString;  
  27. SqlConnection con = new SqlConnection(constring);  
  28. if (comboBox1.Text == "BD_NameConn")  
  29. {  
  30. SqlDataAdapter Sda = new SqlDataAdapter ("Select BD_NameConn, BD_BaseType, BD_Base, BD_Serer, BD_User, BD_MenuStyle FROM BD WHERE BD_NameConn '" + textBox1.Text + "%'",con);  
  31. DataTable Dt = new DataTable();  
  32. Sda.Fill(Dt);  
  33. dataGridView1.DataSource = Dt;  
  34. }  
  35. }  
  36. }  
  37. }  
it stops in the line Sda.Fill (Dt); and displays the message :

System.Data.SqlClient.SqlException*: 'Syntaxe incorrecte vers 's%'.'

I await your help and thank you in advance

Answers (3)