Use of MySQLLoader witha DataSet

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
nuntio2000

Use of MySQLLoader witha DataSet

Post by 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 ?

Oleg
Devart Team
Posts: 264
Joined: Thu 28 Oct 2004 13:56

Re: Use of MySQLLoader witha DataSet

Post by 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
  }
}

nuntio2000
Posts: 19
Joined: Fri 19 Nov 2004 18:51
Location: South Italy

OK

Post by nuntio2000 » Sat 20 Nov 2004 10:14

It works perctly!!
:D

Post Reply