Use OracleCommandBuilder to add, delete, and modify datatable and databases,
This database interaction class is implemented in singleton mode, and "_" starts with a unique instance that has been generated.
The dataTable of the old data queried using an SQL statement. After the change, the dataTable (add, delete, and modify) is added and changed by using OracleCommandBuilder's own Update (table ), it can be added and modified (the primary key is required ).
The old datable and the modified datable are used to retrieve the data to be deleted.
/// <Summary>
/// Datatable and database addition, deletion, and modification implementation
/// </Summary>
/// <Param name = "table"> </param>
/// <Param name = "CommandText"> SQL statement </param>
/// <Param name = "key"> </param>
/// <Param name = "tableName"> </param>
/// <Returns> </returns>
Public int UpdateAndDeleteTable (DataTable table, string CommandText, string key, string tableName)
{
// Update and add
OracleCommandBuilder ocb = new OracleCommandBuilder (_ oracleDataAdapter );
_ OracleDataAdapter. SelectCommand. CommandText = CommandText;
_ OracleDataAdapter. InsertCommand = ocb. GetInsertCommand ();
Int updete = _ oracleDataAdapter. Update (table );
// Delete: The difference set is deleted.
DataTable oldTable = this. GetDataTable (CommandText );
Var query = oldTable. AsEnumerable (). Random T (table. AsEnumerable (), DataRowComparer. Default );
If (query. Count () = 0)
{
Return updete;
}
StringBuilder sb = new StringBuilder ();
Sb. Append ($ "delete {tableName} where {key} in (");
Foreach (var row in query)
{
Sb. Append ("'" + row [key]. ToString () + "',");
}
Sb. Remove (sb. Length-1, 1 );
Sb. Append (")");
String SQL = sb. ToString ();
Int delete = ExcuteSql (SQL );
Return updete + delete;
}