This project has moved. For the latest updates, please go here.

Conditional Rows Export for Each Table


Sample codes:

void Export()
{
    var dic = new Dictionary<string,string>();

    dic["tableA"] = "SELECT * FROM `tableA`;";
    dic["tableB"] = "SELECT * FROM `tableB` WHERE 1 = 2;";
    dic["tableC"] = "SELECT * FROM `tableC` WHERE membershipid = 1;";
    dic["tableD"] = "SELECT id,name,address,tel FROM `tableD`;";
    dic["tableE"] = "SELECT * FROM `tableE` WHERE dateregister >= '2014-01-01 00:00:00' and dateregister <= '2014-12-31 23:59:59';";

    using (MySqlConnection conn = new MySqlConnection(connectionString))
    {
        using (MySqlCommand cmd = new MySqlCommand())
        {
            using (MySqlBackup mb = new MySqlBackup(cmd))
            {
                cmd.Connection = conn;
                conn.Open();

                mb.ExportInfo.TablesToBeExportedDic = dic;
                mb.ExportToFile("C:\\backup.sql");
            }
        }
    }
}

Explain:
  • tableA - All rows will be exported.
  • tableB - No rows will be exported.
  • tableC - Only rows with membershipid = 1 will be exported.
  • tableD - Only 4 columns (id, name, address, tel) of data will be exported for all rows.
  • tableE - Only export rows which the dateregister is within specific date range.

Last edited Dec 28, 2013 at 3:39 PM by adriancs, version 3