Use of MySQLLoader witha DataSet

Use of MySQLLoader witha DataSet

Postby nuntio2000 » Thu 18 Nov 2004 08:43

Hi,
how can I use MySQLLoader to INSERT a dataset into the database?
Could you write same code lines for sample please ?
nuntio2000
 

Re: Use of MySQLLoader witha DataSet

Postby Oleg » Thu 18 Nov 2004 13:26

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
  }
}
Oleg
Devart Team
 
Posts: 264
Joined: Thu 28 Oct 2004 13:56

OK

Postby nuntio2000 » Sat 20 Nov 2004 10:14

It works perctly!!
:D
nuntio2000
 
Posts: 19
Joined: Fri 19 Nov 2004 18:51
Location: South Italy


Return to dotConnect for MySQL