Visual Studio generated Update Queries.. Is this the way to go?

  • Thread starter Thread starter W.G. Rowland
  • Start date Start date
W

W.G. Rowland

I'm fairly new to SQL Server, and I've been using Visual Studio to help
generate some SQLCommands to make life easier. The Insert, Delete, and
Select Commands it produces all seem fairly straightforward, but I'm
wondering about the Update Commands it generates.

Basically what it seems to do is generate an Update command with parameters
for each property, and then a second parameter for each property in the
Where clause.. So to update a record, it would expect you to enter every
column value of the record to be updated, and then all the new values as
well..

In my case I will always be using the unique identity column to select which
record I'm going to update, and I'm wondering if there's any reason (such as
some effeciency issue in SQL I don't know about) to requre my code to supply
every property in the where clause, or if I could just trim all the extra
parameters and have it simply update record WHERE ID=@parameterID..?

Thanks in advance,
William Rowland
 
Data Consistency.

The generated queries are checking that the data has not already been
changed before overwriting your changes; that way you should not lose any
changes made by somebody else.
 
Take a minute and read my article on the Command(don't use)Builder. It will
shed some light on its functions, malfunctions and mysteries.
See www.betav.com/articles.htm

These auto-generated or runtime generated queries work fine in simple
situations, but fall apart when you start building serious apps.

hth
--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Thanks.. Don't laugh (or do), but I was actually using the auto-generated
queries as sort of a lazy typist.. I'm building custom objects for data
access. Once I figured out I had to write command objects to Update,
Insert, and Delete records I realized I was going to have to write a whole
lot of parameter objects, so I used VS dataset object to build the Stored
Procedures, then cut and pasted the parameter creation code it created into
my objects (I'm sure there are better ways to do this, but it saved a LOT of
grunt work..)

The app is a single tier that will have sole access to the database (SQL
Desktop running on the client machine), so I don't have to worry about
concurrent edits or anything like that. So think I'm safe just calling
updates based on the identity field of the table..

Thanks again,
W.G. Rowland
 
Nope, I'm not laughing.. There are lots of folks like you that (correctly)
use the CommandBuilder to save time. The problem is, there are folks trying
to build serious multi-user, high-performance applications that use the CB
and don't understand why their action queries run so slowly.



--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Have you taken a look at Codesmith by Eric J. Smith? It's
a code generator that will do the things that you have
been describing. If you dont like the code it generates
then you can just go straight ahead and tweak the template
to get what you do want.

The whole prog fits on one floppy and the price can't be
beat!

Regards
 
Back
Top