开发者

How to refresh datagridview binding in vb.net or C#?

开发者 https://www.devze.com 2023-03-13 19:40 出处:网络
I created two tables(FIRSTtable and SECONDtable) in the mysql database and two tables that are related.

I created two tables(FIRSTtable and SECONDtable) in the mysql database and two tables that are related.

The FIRST table, has a columns (product_id (pK), product_name). The SECOND table has an columns (machine_id, production_date, product_id (fK), product_quantity, operator_id).

Relations between the two tables using the product_id column with UpdateCascade and DeleteCascade. Both relationships are functioning normally when I try with the sql script. Suppose I delete all product_id in the FIRST table, all existing data in the SECOND table will be deleted.

Both of these tables displayed in datagridview. When I delete all the data in the FIRST table, the all rows in datagridview FIRST table will be deleted, also the data in mysql the FIRST table will be deleted.

I try 开发者_开发百科to open the mysql database, the data are in SECOND Table also deleted, the problem why the view that in the second datagridview, can not be deleted, still keep the previous data? How to refresh datagridview binding in vb.net or C#? Thanks.

    With Me.SECOND_DataGridView
        .Datasource = Nothing  ' tried this, but failed.
        .DataSource = MyDataset.Tables("SECOND_table")
    End With


I believe what you are running into is the fact the the MySQL Engine is actually performing the cascading deletes for you.

When you query the MySQL Data into a localized C# "DataTable" (Table within a DataSet), that data is now in memory and not directly linked to that on the disk. When you go to delete the rows in the "memory" version of the first data table, its causing the deletions to occur at the SERVER for the second level table and NOT directly updating you in-memory version of data table two.

That being said, you will probably have to do one of two things... Requery the entire dataset (tables one and two) to get a full refresh of what is STILL in the actual database... OR... As you are calling the delete from table one of the dataset, you'll have to perform the delete handling in the local datatable TWO as well to keep it in synch.

0

精彩评论

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