使用Entitiy Framework将数据从一个数据库传输到另一个数据库似乎并不简单。所以我再试一次数据表& dataadapters:
MySqlDataAdapter dataAdapter = new MySqlDataAdapter();
MySqlCommand command = connection.CreateCommand();
string query2 = "SELECT * FROM `" + targetTable + "`";
command.CommandText = query2;
dataAdapter.SelectCommand = command;
DataTable tableToUpdate = new DataTable("myTable");
dataAdapter.FillSchema(tableToUpdate, SchemaType.Source);
dataAdapter.Fill(tableToUpdate);
// an den DataAdapter übergeben
MySqlCommandBuilder myComBuilder = new MySqlCommandBuilder(dataAdapter);
dataAdapter.UpdateCommand = myComBuilder.GetUpdateCommand();
dataAdapter.InsertCommand = myComBuilder.GetInsertCommand();
tableToUpdate.Merge(sourceDT,false);
int changeCount = dataAdapter.Update(tableToUpdate);s
DataTable changes = tableToUpdate.GetChanges();
更新和插入命令似乎是正确的,但数据库中没有更新任何内容?
编辑: 问题似乎在于dataTables的合并。不添加新列。添加了新行但Rowstate未更改。