문제

I've got a simple table in an MS Access database:

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

Then using the Visual Studio wizard I generate the corresponding DataTable and TableAdapter.

The generated Select statement looks just as expected:

SELECT Id, Name, Path, Notes
FROM Programs

But the generated Update statement is very complicated:

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 = ?)

Why is it generated so complicated? Why isn't it much simpler, something like this:

UPDATE Programs
SET Id = ?, Name = ?, Path = ?, Notes = ?
WHERE  (Id = ?)
도움이 되었습니까?

해결책

Because the query detects if changes have been made to the database since last select. You can turn this kind of check off to simplfy the query.

From the 'TableAdapter Configuration Wizard', select 'Advanced Options..." and uncheck 'Use optimistic concurrency'

See Optimistic Concurrency (ADO.NET) at http://msdn.microsoft.com/en-us/library/aa0416cz.aspx.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top