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. Can I run query on data shown in DataGrid?

Can I run query on data shown in DataGrid?

Scheduled Pinned Locked Moved C#
databasemysqlsysadminquestion
5 Posts 5 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.
  • K Offline
    K Offline
    Khoramdin
    wrote on last edited by
    #1

    Hello everyone, I have a DataGrid which is populated by data from the Database server. The following codes shows this. // 2. Start DataGridView "dataGridView1". // 2a. create a mysql DataAdapter OdbcAd = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM " + SelectedTableName + ";", OdbcCon); // 2b. create a dataset DataSet myds = new DataSet(); // 2c. now fill and bind the DataGrid OdbcAd.Fill(myds, SelectedTableName); // 2d. dataGridView1.DataSource = myds; dataGridView1.DataSource = myds.Tables[SelectedTableName]; I was wondering if it is possible to run queries on the DataGrid's data similar to the one that can be run on the data stored in database server? Thank you very much and have a great day. Khoramdin

    E J J A 4 Replies Last reply
    0
    • K Khoramdin

      Hello everyone, I have a DataGrid which is populated by data from the Database server. The following codes shows this. // 2. Start DataGridView "dataGridView1". // 2a. create a mysql DataAdapter OdbcAd = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM " + SelectedTableName + ";", OdbcCon); // 2b. create a dataset DataSet myds = new DataSet(); // 2c. now fill and bind the DataGrid OdbcAd.Fill(myds, SelectedTableName); // 2d. dataGridView1.DataSource = myds; dataGridView1.DataSource = myds.Tables[SelectedTableName]; I was wondering if it is possible to run queries on the DataGrid's data similar to the one that can be run on the data stored in database server? Thank you very much and have a great day. Khoramdin

      E Offline
      E Offline
      EvilInide
      wrote on last edited by
      #2

      In my aspect, data grid is only for displaying data as in tabular format, not to query information evil

      1 Reply Last reply
      0
      • K Khoramdin

        Hello everyone, I have a DataGrid which is populated by data from the Database server. The following codes shows this. // 2. Start DataGridView "dataGridView1". // 2a. create a mysql DataAdapter OdbcAd = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM " + SelectedTableName + ";", OdbcCon); // 2b. create a dataset DataSet myds = new DataSet(); // 2c. now fill and bind the DataGrid OdbcAd.Fill(myds, SelectedTableName); // 2d. dataGridView1.DataSource = myds; dataGridView1.DataSource = myds.Tables[SelectedTableName]; I was wondering if it is possible to run queries on the DataGrid's data similar to the one that can be run on the data stored in database server? Thank you very much and have a great day. Khoramdin

        J Offline
        J Offline
        Justin Bozonier
        wrote on last edited by
        #3

        Hi, You would actually run your "query" on the DataSet. By that I mean you can filter and sort it. Here is an example: http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/FilterData.aspx Reply back if you have more questions! Justin

        1 Reply Last reply
        0
        • K Khoramdin

          Hello everyone, I have a DataGrid which is populated by data from the Database server. The following codes shows this. // 2. Start DataGridView "dataGridView1". // 2a. create a mysql DataAdapter OdbcAd = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM " + SelectedTableName + ";", OdbcCon); // 2b. create a dataset DataSet myds = new DataSet(); // 2c. now fill and bind the DataGrid OdbcAd.Fill(myds, SelectedTableName); // 2d. dataGridView1.DataSource = myds; dataGridView1.DataSource = myds.Tables[SelectedTableName]; I was wondering if it is possible to run queries on the DataGrid's data similar to the one that can be run on the data stored in database server? Thank you very much and have a great day. Khoramdin

          J Offline
          J Offline
          Jaiprakash M Bankolli
          wrote on last edited by
          #4

          My understanding say that you can't query dataset, but what best you can do is to filter the dataset - datatable to fect the required information and bind it again.

          Regards, Jaiprakash M Bankolli jaiprakash.bankolli@gmail.com My Blog Suggestions for me

          1 Reply Last reply
          0
          • K Khoramdin

            Hello everyone, I have a DataGrid which is populated by data from the Database server. The following codes shows this. // 2. Start DataGridView "dataGridView1". // 2a. create a mysql DataAdapter OdbcAd = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM " + SelectedTableName + ";", OdbcCon); // 2b. create a dataset DataSet myds = new DataSet(); // 2c. now fill and bind the DataGrid OdbcAd.Fill(myds, SelectedTableName); // 2d. dataGridView1.DataSource = myds; dataGridView1.DataSource = myds.Tables[SelectedTableName]; I was wondering if it is possible to run queries on the DataGrid's data similar to the one that can be run on the data stored in database server? Thank you very much and have a great day. Khoramdin

            A Offline
            A Offline
            AFSEKI
            wrote on last edited by
            #5

            Try DataTable.Select(string filterExpression9 of the underlying datasource ( in your case: SelectedTable ) and hide the rows in your datagridview which are not in the result set returned by this method. What I would do is, not to modify original datasource which is "SelectedTableName", but execute SelectedTable.Select(....) and store the result in thze Tag value of the DataGrid which is a object value. Then set the datasource to this result set. Afterwards, if you want to see the original(non-filtered) rows, you won't need to retrieve them from the data store again. Hope this helps.

            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