lundi 29 février 2016

Read DataSet from MySQL and update it at a SqLite database

I found this related Question, but it doesn't work for me that way. My implementation looks like follows:

 public void SyncWithMySQL(List<Tuple<String, String>> queriesTableName, DataSet mysqlDataSet, params KeyValuePair<string, object>[] cmdParams)
    {
        foreach (Tuple<String, String> queryTableName in queriesTableName)
        {
            using (var cmd = this._connection.CreateCommand()) { 
                cmd.CommandText = queryTableName.Item2;

                foreach (var p in cmdParams)
                {
                    cmd.Parameters.AddWithValue(p.Key, p.Value);
                }

                SQLiteDataAdapter adap = new SQLiteDataAdapter(cmd);
                using (adap.InsertCommand = new SQLiteCommandBuilder(adap).GetInsertCommand())
                {
                    System.Diagnostics.Trace.TraceInformation(adap.InsertCommand.CommandText);
                    int rows = adap.Update(mysqlDataSet.Tables[queryTableName.Item1]);
                    System.Diagnostics.Trace.TraceInformation("Table " + queryTableName.Item1 + " update: " + rows);
                }
            }
        }
    }

where mysqlDataSet is the dataset i want to store in the sqlite database, queriesTableName is list of tuples where the tuple contains of th name of the table and the query for each table.

The strange thing is, i don't get an error and the update method of the DataAdapter returns values greater 0. So actually they should be data in the database, but unfortunately its not the case

The DataSet from the MySQL database is filled with this command:

MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
adap.AcceptChangesDuringFill = false;
adap.Fill(result, queryTableName.Item1);

Is there something wrong with my code? Do i miss something? Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire