Page 1 of 1

Use of MySQLLoader witha DataSet

Posted: Thu 18 Nov 2004 08:43
by nuntio2000
Hi,
how can I use MySQLLoader to INSERT a dataset into the database?
Could you write same code lines for sample please ?

Re: Use of MySQLLoader witha DataSet

Posted: Thu 18 Nov 2004 13:26
by Oleg
You can load data from DataSet into MySQL database using the next code sample:

Code: Select all

/// 
/// Tables must be created before you call this function
/// 
/// if you have InnoDB table, set this parameter = false
void CopyDataSet(DataSet dataset, string connectionString, bool delayed) {

  MySqlConnection connection = new MySqlConnection(connectionString);
  connection.Open();

  MySqlLoader loader = new MySqlLoader();
  loader.Connection = connection;
  loader.Delayed = delayed;

  foreach (DataTable table in dataSet.Tables) {
    loader.TableName = table.TableName;
    loader.CreateColumns();
    loader.Open();

    foreach (DataRow row in table.Rows) {
      for (int i = 0; i < table.Columns.Count; ++i)
        loader.SetValue( i, row[i]);
      loader.NextRow();
    }
    loader.Close(); // flush table to database
  }
}

OK

Posted: Sat 20 Nov 2004 10:14
by nuntio2000
It works perctly!!
:D