在MS Access数据库更新链接表与C#编程 [英] Update linked tables in MS Access Database with C# programatically

查看:245
本文介绍了在MS Access数据库更新链接表与C#编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Access 2003数据库( fooDb barDb )。有在 fooDb 四个表是在 barDb 挂表。

I have two Access 2003 databases (fooDb and barDb). There are four tables in fooDb that are linked to tables in barDb.

两个问题:

  • 如何更新表的内容(链接表 fooDb barDb 与表的内容进行同步)
  • 如何重新链接表以不同的 barDb 使用 ADO.NET
  • How do I update the table contents (linked tables in fooDb should be synchronized with the table contents in barDb)
  • How do I re-link the table to a different barDb using ADO.NET

我用Google搜索,但没有得到任何有用的结果。我发现了是如何做到这一点在VB(6)和DAO,但我需要C#中的解决方案。

I googled but didn't get any helpful results. What I found out is how to accomplish this in VB(6) and DAO, but I need a solution for C#.

推荐答案

如果你的编码在C#中,然后访问不涉及,只喷。所以,你可以使用任何方法,你要访问的数据,然后code更新。

If you're coding in C#, then Access is not involved, only Jet. So, you can use whatever method you want to access the data and then code the updates.

我有codeD这种事情在访问了很多次,我的方法为每个表是:

I've coded this kind of thing in Access many times, and my approach for each table is:

  1. 运行,删除从fooDB在barDB不再存在的查询。

  1. run a query that deletes from fooDB that no longer exist in barDB.

运行插入到fooDB记录是barDB那些尚未fooDB存在的查询。

run a query that inserts into fooDB records that are in barDB that do not yet exist in fooDB.

我总是用code,它写在即时SQL与来自barDB数据更新fooDB表。

I always use code that writes on-the-fly SQL to update the fooDB table with the data from barDB.

第三的是硬的。我穿过田野收集DBA循环和动态,将是这样写的SQL:

The 3rd one is the hard one. I loop through the fields collection in DBA and write SQL on the fly that would be something like this:

UPDATE table2 INNER JOIN table1 ON table2.ID = table1.ID
SET table2.field1=table1.field1
WHERE (table2.field1 & "") <> (table1.field1 & "")

对于数字字段你必须使用你提供SQL语言的功能,将零至零。喷气运行的SQL,我会使用新西兰(),当然,但是,这并不通过ODBC工作。不知道它会与OLEDB工作,虽然。

For numeric fields you'd have to use your available SQL dialect's function for converting Null to zero. Running Jet SQL, I'd use Nz(), of course, but that doesn't work via ODBC. Not sure if it will work with OLEDB, though.

在任何情况下,关键是要发布,而不是试图做到这一点按行,这将是非常低效排了一堆列逐列SQL更新。

In any event, the point is to issue a bunch of column-by-column SQL updates instead of trying to do it row by row, which will be much less efficient.

这篇关于在MS Access数据库更新链接表与C#编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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