我在 MS Access 数据库中有一个简单的表:
-------------------
| Programs |
|-----------------|
| Id (PrimaryKey) |
| Name |
| Path |
| Notes |
-------------------
然后使用 Visual Studio 向导生成相应的DataTable
和TableAdapter
.
生成的 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 = ?)