开发者

Datagridview : how to reload the data?

开发者 https://www.devze.com 2023-04-11 14:40 出处:网络
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 repo

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

Datagridview : how to reload the data?

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号