Tuesday, November 27, 2007

Usmc Motorcycle Helmet

Insert dataset VS2005

Using VS2005 typed dataset data layer as it saves a lot of time because it creates self a whole layer of classes, methods and queries (for SQL: this is the environment that I use) that can be used by the business layer above.

Today I discovered something rather alarming, at least as long as they do not know.

I focus on the method to insert a table in the dataset. You can choose between text or stored procedure or table direct.
If you choose text, you can enter text in two ways:
- using the query builder (clicking on the appropriate 3 dots in the CommandText property);
- by entering the query at hand (maybe doing a copy / paste from SQL manager).

But there is a significant difference between the two methods: first it appends "sneak" a select command in accordance with the insert command that we just edited. Select
This is essential because it serves to bring the new values \u200b\u200bfrom the database to the dataset, in the absence of the select, remains with the old values.
The most striking case is when the insert affects the rows in a table that has auto-increment an index: auto-increment on both the db (with positive step) on both the db (with negative step) *.
In this case the indices of the rows just inserted the db will keep the index change was negative, but to be added unchanged. At a subsequent change in status will generate a Modified exception of lack of primary key during UPDATE, because the adapter will rely on the index line remained negative and scrambled from the db.



*: why it is useful to step negative indexes in the database for auto-increment reference to MS documentation.

0 comments:

Post a Comment