Hi,
how can I use MySQLLoader to INSERT a dataset into the database?
Could you write same code lines for sample please ?
Use of MySQLLoader witha DataSet
Re: Use of MySQLLoader witha DataSet
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
}
}