I am using a search textbox (TxtNameSearch) to filter data in a datagridview in a C# Winforms application in Visual Studio, where an user will enter a certain primary key (i.e. NameID) in the search box to filter the results in the datagridview. It throws the error which is noted in the title.
private void TxtNamecSearch_TextChanged(object sender, EventArgs e) { DataView dtvNames = new DataView(dtNames); dtvNames.RowFilter = string.Format("Convert (NameID,'System.String') Like '%{0}%'", TxtNameSearch.Text); // Errror occurs on this line NameDataGridView.DataSource = dtvNames; }
I expect to type in the textbox, the primary key [NameID] which is a numeric number and the results in the datagridview will automatically filter by the column "NameID"