2个数据库之间的数据交换 [英] Data exchange between 2 databases

查看:222
本文介绍了2个数据库之间的数据交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我在服务器数据库和移动数据库(sdf)的数据交换方面遇到了很大的问题.
首先,我将具有正常选择权限的数据从服务器加载到我的DataSet中,然后
我设置要添加的表行,并使用DataTableAdapter.Update()命令填充移动数据库.

如果我第二次这样做,则会出现问题,因为我遇到了一个主键冲突的异常.在填写移动数据库之前,我先用
删除整个表 删除命令.

如果移动数据库中没有数据,为什么会出现这样的异常?

亲切的问候,
thomas

Hello!

I have a huge problem with the data exchange of a server database and a mobile database( sdf ).
At first I load the data with a normal select from the server to my DataSet and then
i set the table rows to added and use the DataTableAdapter.Update() command to fill the mobile database.

The problem appears if I do it a second time because I got an exception with a primary key violation. Before i fill my mobile db I delete the whole table with the
delete-command.

Why do i get such an exception if no data is in my mobile database??

Kind regards,
thomas

推荐答案

看到代码会有所帮助,但是您这样做了吗:
-插入后接受数据表中的更改
-在重新插入之前清除数据表中的所有行(我的意思是您在数据表中没有重复的内容)
Seeing the code would help, but did you:
- accept the changes in the datatable after inserting
- clear all the rows from the data table before re-inserting (I mean you don''t have duplicates in the datatable)


"table"变量是我从ServerDB.

因此,我尝试删除移动Ce DB中的整个表,然后在该表中插入数据.

第一次工作,第二次由于上述主键冲突而失败.

我认为DataTableAdapter应该在插入并清除表后接受该更改,然后再重新填充数据.

The "table" variable is my full loaded DataTable from the ServerDB.

So I try to delete the whole table in my mobile Ce DB and then to insert the data in this one.

The first time it works, the second time it fails because of the above mentioned primary key violation.

I think the DataTableAdapter should accept the changes after the insert and the table is cleared before refill the data.

_adpList[table.TableName].InsertCommand.Connection.Open();
     new SqlCeCommand("Delete From " + table.TableName, (SqlCeConnection)_adpList[table.TableName].SelectCommand.Connection).ExecuteNonQuery();
     _adpList[table.TableName].InsertCommand.Connection.Close();

      for (int i = 0; i < table.Rows.Count; i++)
      {
          table.Rows[i].SetAdded();
      }


      int rows = _adpList[table.TableName].Update(table);


这篇关于2个数据库之间的数据交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆