Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. search button

search button

Scheduled Pinned Locked Moved C#
questionhelp
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    faladrim
    wrote on last edited by
    #1

    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

    W 1 Reply Last reply
    0
    • F faladrim

      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

      W Offline
      W Offline
      Wjousts
      wrote on last edited by
      #2

      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 + "%'";

      F 1 Reply Last reply
      0
      • W Wjousts

        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 + "%'";

        F Offline
        F Offline
        faladrim
        wrote on last edited by
        #3

        what if i have 100 columns??

        E W 2 Replies Last reply
        0
        • F faladrim

          what if i have 100 columns??

          E Offline
          E Offline
          Eric Dahlvang
          wrote on last edited by
          #4

          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

          F 2 Replies Last reply
          0
          • E Eric Dahlvang

            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

            F Offline
            F Offline
            faladrim
            wrote on last edited by
            #5

            even 10 i find alot to write the query over and over for every colmn i need something were i could say: allcolmns like'%"+textbox.text"%'"; or is there no sutch thing?

            1 Reply Last reply
            0
            • E Eric Dahlvang

              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

              F Offline
              F Offline
              faladrim
              wrote on last edited by
              #6

              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...

              E 1 Reply Last reply
              0
              • F faladrim

                what if i have 100 columns??

                W Offline
                W Offline
                Wjousts
                wrote on last edited by
                #7

                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();

                1 Reply Last reply
                0
                • F faladrim

                  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...

                  E Offline
                  E Offline
                  Eric Dahlvang
                  wrote on last edited by
                  #8

                  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

                  F 1 Reply Last reply
                  0
                  • E Eric Dahlvang

                    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

                    F Offline
                    F Offline
                    faladrim
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups