How to update tables in a relational database RRS feed

  • Question

  • I’m using several sql statements with nested JOIN to populate a data grid view like this:


    Code Block

    sSQL = "SELECT DISTINCT [tbCar100].[Car100_ID], tbCar100.Description100 AS [Caractéristique 100], " & _

                "[tbCar200].[Car200_ID], tbCar200.Description200 AS [Caractéristique 200] " & _

                "FROM (tbCar200 INNER JOIN tbIntersect ON tbCar200.Car200_ID = tbIntersect.Car200_ID) INNER JOIN tbCar100 " & _

                "ON tbIntersect.Car100_ID = tbCar100.Car100_ID WHERE tbCar100.Car100_ID = " & ID1.ToString()




    Then, I want to let the user modify the data on data grid view and update the database tables accordingly.


    Of course, I cannot use DataAdapter.UpdateCommand for this because there are several tables involved.


    My question is: how can I keep track of where the data came from on the data grid so that I can update the respective table easily? Data can come from different tables depending on the situation, on what the user selected before.


    Monday, October 29, 2007 2:19 PM

All replies

  • You would need to bring the values of the primary key columns from each table. When the user has made it changes you could create a SQL statement that contains many UPDATE statements, but I would recommend you to do a stored procedure that takes all your columns as parameters and in the stored procedure runs each UPDATE statement for each table.


    Hope this helps.

    Thursday, November 1, 2007 8:35 PM