Reputation: 2577
I have a MysqlTable adapter, and a Dataset being used like this:
string sql = "SELECT firstName,lastName,phoneNumber FROM customers";
daCustomers = new MySqlDataAdapter(sql, conn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(daCustomers);
dsCustomers = new DataSet();
daCustomers.Fill(dsCustomers, "customers");
dataGridView1.DataSource = dsCustomers;
dataGridView1.DataMember = "customers";
Is there a way to filter what is shown in the dataGridView without reloading the data?
Upvotes: 0
Views: 120
Reputation: 18843
there are several ways you can do this.. for example create a Method that returns a DataSet
public DataSet GetCustomers()
{
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT firstName,lastName,phoneNumber FROM customers", conn);
DataSet custDS = new DataSet();
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
adapter.Fill(custDS, "Customers");
return custDS;
}
if you return the DataTable
public DataTable GetCustomers()
{
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT firstName,lastName,phoneNumber FROM customers", conn);
DataSet custDS = new DataSet();
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
adapter.Fill(custDS, "Customers");
return custDS.Tables[0];
}
Upvotes: 1
Reputation: 5737
You can bind a DataView
instead of a DataTable
and set a filter string (property .RowFilter
) there.
Upvotes: 0