I have a populated Datagridview, which gets its data from a DataTableAdapter.
I have a separate button on my form. When I click the button 开发者_如何学PythonI want the DataTable to refresh and repopulate completely.
Seems so easy, but I can't find a way to do this.
Thanks in advance
If you wish to swap the code for dynamic grid functionality, right click on your datatable and add a new query (green box in the SS):
Select * from tablename
Then go locate the line in the form_load that takes care of the data population:
this.yourTableAdapter.Fill(this.yourDataSet.yourdatatable);
The default SQL query is always called .Fill, but in case you add a new query the second one will be called (orange box in SS):
this.yourTableAdapter.FillBy(this.yourDataSet.yourdatatable);
By running this second method somewhere in your code (a button press maybe) the grid should change to the new sql command and display the new results in the gridview:
protected void Button1_Click(object sender, EventArgs e)
{
this.yourTableAdapter.FillBy(this.yourDataSet.yourdatatable);
}
精彩评论