我正在将数据从 SQL 服务器复制到 mysql。我从 sql server 加载一个表,从 mysql 加载一个表并复制数据。数据被复制到新表中,但数据库中的表仍然为空。提前致谢。这是我的代码 -
private void WriteTable(DataTable table, string tablename)
{
long maxid=0;
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from " + tablename, mysqlConn);
MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(cmd);
DataTable dest = new DataTable();
adapter.Fill(dest);
txtMessages.Text += table.Rows.Count.ToString()+"\r\n";
foreach (DataRow row in table.Rows)
{
DataRow newrow = dest.NewRow();
newrow.BeginEdit();
foreach (DataColumn col in table.Columns)
{
newrow[col.Caption] = row[col.Caption];
}
newrow.EndEdit();
dest.Rows.Add(newrow);
maxid = long.Parse(row["RowID"].ToString());
txtMessages.Text += maxid.ToString() + "\r\n";
SetRowID(tablename, maxid);
}
MySql.Data.MySqlClient.MySqlCommandBuilder builder = new MySql.Data.MySqlClient.MySqlCommandBuilder(adapter);
adapter.DeleteCommand = builder.GetDeleteCommand();
adapter.InsertCommand = builder.GetInsertCommand();
adapter.UpdateCommand = builder.GetUpdateCommand();
dest.AcceptChanges();
adapter.Update(dest);
}