search button
-
-
hi, how do i make my search go over my entire table, i can do it on one colmn: db1DataSet.Tabel1.DefaultView.RowFilter = " column1 LIKE '%" + txt_sort.Text + "%' "; dataGridView1.DataSource = db1DataSet.Tabel1.DefaultView; can somebody help? thx
faladrim wrote:
how do i make my search go over my entire table
What do you mean? A search will go over your entire table (i.e. every row in the table matching the row filter). Do you mean how do you filter multiple columns? In that case you can just AND (or OR) your filters together:
MyDataTable.DefaultView.RowFilter = "column1 LIKE '%" + myCol1String + "%' AND column2 LIKE '%" + myCol2String + "%'";
-
faladrim wrote:
how do i make my search go over my entire table
What do you mean? A search will go over your entire table (i.e. every row in the table matching the row filter). Do you mean how do you filter multiple columns? In that case you can just AND (or OR) your filters together:
MyDataTable.DefaultView.RowFilter = "column1 LIKE '%" + myCol1String + "%' AND column2 LIKE '%" + myCol2String + "%'";
-
faladrim wrote:
what if i have 100 columns??
Then it is likely that your database needs redesigning. Disclaimer: I understand that there are cases where tables require 100+ columns. But, from what I've seen, most tables of this size should in fact be broken up into smaller tables with one to one relationships.
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
faladrim wrote:
what if i have 100 columns??
Then it is likely that your database needs redesigning. Disclaimer: I understand that there are cases where tables require 100+ columns. But, from what I've seen, most tables of this size should in fact be broken up into smaller tables with one to one relationships.
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
faladrim wrote:
what if i have 100 columns??
Then it is likely that your database needs redesigning. Disclaimer: I understand that there are cases where tables require 100+ columns. But, from what I've seen, most tables of this size should in fact be broken up into smaller tables with one to one relationships.
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
i am trying to figger something out to recreate the query for (colnr =1; colnr =colamount;colnr++) { string colname= dataset.table.colmns[colnr].tostring(); } by this i get all the names of the colmns wright? so if i could get this in the query, ill try it for one column: string colname = dataset.table.colmns[1].tostring(); // get name of col 1 db1DataSet.Tabel1.DefaultView.RowFilter = colname+" LIKE '%" + txt_sort.Text + "%' "; dataGridView1.DataSource = db1DataSet.Tabel1.DefaultView; this should do the same as entering the real name of the column just befor" LIKE" but here i get an error...
-
faladrim wrote:
what if i have 100 columns??
So firstly I agree with EricDV, you probably need to rethink the way you are organizing your data. Secondly, you can create the query string in a loop. Something like this (untested code):
// colFilters is an array of strings with the text you are using to filter // for each column StringBuilder sb = new StringBuilder; for (int i=0; i <myTable.Columns.Count; i++) { sb.Append(myTable.Columns[i].ColumnName + " LIKE '%" + colFilters[i] + "%'"); if (i <myTable.Columns.Count-1) sb.Append(" AND "); } . . . MyTable.DefaultView.RowFilter = sb.ToString();
-
i am trying to figger something out to recreate the query for (colnr =1; colnr =colamount;colnr++) { string colname= dataset.table.colmns[colnr].tostring(); } by this i get all the names of the colmns wright? so if i could get this in the query, ill try it for one column: string colname = dataset.table.colmns[1].tostring(); // get name of col 1 db1DataSet.Tabel1.DefaultView.RowFilter = colname+" LIKE '%" + txt_sort.Text + "%' "; dataGridView1.DataSource = db1DataSet.Tabel1.DefaultView; this should do the same as entering the real name of the column just befor" LIKE" but here i get an error...
int colnr;
int colamount = db1DataSet.Tables[0].Columns.Count;
string cFilter = "";for (colnr = 0; colnr < colamount; colnr++)
{
cFilter = cFilter + (cFilter.Length > 0 ? " OR [" : "[") + db1DataSet.Tables[0].Columns[colnr].ColumnName + "] LIKE '%" + txt_sort.Text + "%' ";
}
db1DataSet.Tables[0].DefaultView.RowFilter = cFilter;
dataGridView1.DataSource = db1DataSet.Tables[0].DefaultView;--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
int colnr;
int colamount = db1DataSet.Tables[0].Columns.Count;
string cFilter = "";for (colnr = 0; colnr < colamount; colnr++)
{
cFilter = cFilter + (cFilter.Length > 0 ? " OR [" : "[") + db1DataSet.Tables[0].Columns[colnr].ColumnName + "] LIKE '%" + txt_sort.Text + "%' ";
}
db1DataSet.Tables[0].DefaultView.RowFilter = cFilter;
dataGridView1.DataSource = db1DataSet.Tables[0].DefaultView;--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
thxxx im sure it will work, but i most have made an mistake somewere cause i get this error: System.Data.EvaluateException was unhandled Cannot perform 'Like' operation on System.Int32 and System.String." this only happens on a colmn named numbers, in acces i specifided it as text, but i wrote a function to make sure it were numbers. have you ever come across anything like this? its probebly a stupid mistake :D anyway thx for the help grz