I want to search rows in my DataTable.
I’ve tried this:
protected void imggastsuche_Click(object sender, EventArgs e)
{
string searchstring = txtgastsuche.Text;
DataTable tb = DataBaseManager.GetDataTable(mysqlconnectionstring);
DataRow[] foundRows = tb.Select("FIRSTNAME,LASTNAME,NAME,COMPANY,TIMEFROM,TIMETO,CREATOR Like '%" + searchstring + "%'");
tb = foundRows.CopyToDataTable();
this.ListView.DataSource = tb;
this.ListView.DataBind();
}
But I have an error in my string.
What can I do if I want to search these columns?
You get the error because the parameter to
Selectis the filterExpression and you have passed all columns. Understand the filterExpression as aWHEREclause in sql. You want all columns but you want to filter by just one. You get all columns anyway since they are all part of theDataTable/DataViewso you don’t need to list them explicitely.You could either use the
DataTable.Select,DatView.RowFiltermethods orLINQ-to-DataSet:LINQ-To-DataSet (which i prefer):
ADO.NET(
DataTable.Select):ADO.NET(
DataView.RowFilter):If you want to search for this
stringin any column instead:The same with Linq: