Thanks strong thanks to PPOWER.ado multi-table update code, Welcome refers to Xuchaofei@jit.com.tw, // --------------------------------------------------------------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------ Define a structure in .h file: struct fieldValue {Ansistring fnname; variant fnvalue;}; struct fieldinfor {std :: vector myvalue;}; //// ---------- On the private section: std :: Vector myfieldinfor; std :: vector Tablefield; void __fastcall gettheupdatetable (std :: vector & tablename) ; Void __fastcall beforepostev (TDataSet * Dataset); // ----------------------- in the CPP file: in order to order multi-table SQL statements DataSet's BeforePost event is added as follows: BeForePostev (DataSet); // ----------------------- void __fastcall tmutableop :: beforePostev (TDataSet * Dataset) {IF (DataSet-> Modified) {FieldInfor Tempvector; for (int i = 0; i fieldcount; i) {FieldValue Allfield; allfield.fname = DataSet-> Fields-> Fields [i] -> FieldName; allfield.fnvalue = dataset-> fields-> fields [i] -> value; TempVector.MyValue.push_back (allfield); // Save all the contents of the data of the field with the data changed. } Myfieldinfor.push_back (tempvector);}} // ------------------------------- // Hypothesis has obtained After changing the field, then compare it, see the data of that table, and update.
void __fastcall TMutableOp :: GetTheUpdateTable (std :: vector & TableName) {std :: auto_ptr Query (new TADOQuery (NULL)); Query-> Connection = ADOConnection1; // -------- -------------------------------------------------- --- for (std :: size_t i = 0; i
Tempa.delete (1, Tablename [T] .length ()); // remove the table name to Tempa.Delete (1, 5); // Remove _Key to get true field name FieldValue Fieldstruct;
KeyFieldID = TempA; KeyFieldValue = MyFieldInfor [i] .MyValue [j] .FNValue; FieldStruct.FNName = TempA; FieldStruct.FNValue = MyFieldInfor [i] .MyValue [j] .FNValue; TableField.push_back (FieldStruct);} else { FieldValue Fieldstruct; Ansistring Tempa = MyfieldInfor [i] .myvalue [J] .fname ;; Tempa.delete (1, Tablename [T). Dengthth ()); // remove the table name to Tempa.delete (1, 2); // put __ remove
Fieldstruct.fname = Tempa; FieldStruct.fnValue = myfieldinfor [i] .myvalue [j] .fnvalue; Tablefield.push_back (fieldstructure);}
} Else {// If the table name is different, do not do}}} // 3 for // The data of the first table is found, and the synthetic IF of the update SQL statement is made here. Size () == 0) Return; ANSISTRING SQL; SQL = "SELECT"; for (std :: size_t v = 0; V sql-> text = sql; query-> open (); // remove this The table is in line with this ID condition. Then compare, the result of paying the value while (! Query-> EOF) // The result of this SQL statement can only have a record. {For (int F = 0; f fieldcount; f) {if (query-> fields-> fields [f] -> value == TableField [f] .fnvalue; else {query- > Edit (); query-> fields-> fields [f] -> value = TableField [f] .fnvalue; query-> post (); // update back database;}}} query-> next (); Query-> close ();}}} // -------------------------------------- ------------------------------
The button of the update table is: std :: Vector tablename; tablename.push_back ("aa"); // aa is a table name:, insert the name to change to the name of the VECTOR TABLENAME.PUSH_BACK ("BB") // bb is a table name GetTheUpdateTable (Tablename); // ------------------------------------ --------- OK. Record the DataSet to be a batch update mode. Remember, remember. Some bad places are not very good to write the SQL statement. But there is no way. Because I haven't solved the questions I have asked. There are still some places to be unreasonable. If you have done a lot of POST, you will have a record once, if you changed more than 10,000, you can't do it. !!!!!!!!!!!!!!!!!!!!! 1 There are many empty cycles without necessary.
I can only use the SQL statement to add the corresponding identification information: SELECT A.ID AA_KEY_ID, A.NAME AA__NAME, A.STDNO AA__STDNO, B.MARK AS BB__MARK, B.ID AS BB_KEY_ID from AA As A , Bb as b where a.stdno = b.stdno // -------- AA, BB is a table name: The configuation field of each table is given: I use "Table Name _Key Contempted Field Name "to indicate that the name of each field is used:" Table Name __ field name "above SQL statement, if not add information: SQL is like this: SELECT A. ID, A.Name, A.stdno, B.mark, B.ID from AA AA, BB AS B So some of the SQL statements, this is only multi-table modified, deleted, and new code in understanding some code Write on the basis. The principle of implementation is: Record each change over the record and then take this record to classify. Take it to compare it with the database original data, if it is not the same, change it.