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