Question

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 = ?)
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top