1

我在 MS Access 数据库中有一个简单的表:

-------------------
| Programs        |
|-----------------|
| Id (PrimaryKey) |
| Name            |
| Path            |
| Notes           |
-------------------

然后使用 Visual Studio 向导生成相应的DataTableTableAdapter.

生成的 Select 语句看起来和预期的一样:

SELECT Id, Name, Path, Notes
FROM Programs

但是生成的Update语句非常复杂:

UPDATE Programs
SET          Id = ?, Name = ?, Path = ?, Notes = ?
WHERE  (Id = ?) AND (? = 1) AND (Name IS NULL) AND (? = 1) AND (Path IS NULL) OR
                  (Id = ?) AND (? = 1) AND (Name = ?) AND (Path IS NULL) OR
                  (Id = ?) AND (? = 1) AND (Name IS NULL) AND (Path = ?) OR
                  (Id = ?) AND (Name = ?) AND (Path = ?)

为什么生成这么复杂?为什么不是更简单,像这样:

UPDATE Programs
SET Id = ?, Name = ?, Path = ?, Notes = ?
WHERE  (Id = ?)
4

1 回答 1

4

因为查询检测自上次选择以来是否对数据库进行了更改。您可以关闭这种检查以简化查询。

从“TableAdapter 配置向导”中,选择“高级选项...”并取消选中“使用乐观并发”

请参阅http://msdn.microsoft.com/en-us/library/aa0416cz.aspx上的Optimistic Concurrency (ADO.NET)

于 2013-07-10T22:18:09.983 回答