Jayanta Mukherjee

Jayanta Mukherjee

  • 2.1k
  • 120
  • 33.7k

Datagrid updating with previous selection data from combo box !

Apr 23 2022 1:00 AM

When I select an item from the combo box the datagrid should filter its data and show the filtered data in the datagrid. I've implemented the below code on the combo box's SelectionChanged event

			using(SQLiteConnection conn= new SQLiteConnection(@"Data Source="+Path.GetFullPath("./test.db")))

				SQLiteCommand command = new SQLiteCommand("SELECT * FROM tbl WHERE Name LIKE @name", conn);
				command.Parameters.AddWithValue("@name", cmb.Text);
				SQLiteDataAdapter adap = new SQLiteDataAdapter(command);
				DataTable dt = new DataTable("wth");

But when I first select an item from the combo box then datagrid shows nothing, then the 2nd time when I select an item from the combo box it filters the data as per my first selection and shows data in datagrid and so on...

How do I fix this?