Irwsoft Data Framework

Update Record/s of Multi Tables in MySql
Brief Information
EditionsUltimate
ProvidersMySql.
DataschemaTable and View.
TopicsUpdate Multi-tables syntax.

MySql provides escalate update syntax to update records from multi tables using relation tables.


Example : Update record/s in Person table which CountryName is USA.

C# code
// Must declare and initiate a new instance of PersonTable class.
PersonTable person = new PersonTable();

// Set FirstName column with 'USA Citizenship'
person.FirstName.Value = "USA Citizenship";

// Must declare and initiate a new instance of CountryTable class.
CountryTable country = new CountryTable();

// using MySqlUpdateMultipleTable to delete multi tables.
MySqlUpdateMultipleTable update = new MySqlUpdateMultipleTable(person);
// Don’t forget to set connection string !
// NOTE : it is optional if the data-schema class using default connection.

update.ConnectionString = "...";  // [OPTIONAL]

// Set the relation to Country table
update.Tables.InnerJoin(country).On.Compare(person.CountryId, ComparisonOperator.Equal, country.CountryId);

// Specify columns to update
update.Column(Person.FirstName);

// Set where condition CountryName = "USA"
update.Where.Compare(country.CountryName, ComparisonOperator.Equal, "USA");

// Execute the query and return number of rows affected by operation.
int r = delete.Execute();


Related Topics :

Irwsoft Data Ultimate Edition provides all enhanced features of Irwsoft Data Framework and support from irwsoft.