Update Sql in Vb While in a Read Loop
-
October 3rd, 2013,09:16 AM #1
Thread Starter
Registered User
How to use LOOP and SQL to update database
How to utilise a loop and an update query to update all the records of a column?
-
Oct 3rd, 2013,11:52 AM #two
Re: How to use LOOP and SQL to update database
Code:
Do While Not rs.Eof rs!<ColumnName> = value rs.MoveNext Loop
-
October third, 2013,12:22 PM #3
Re: How to use LOOP and SQL to update database
Welcome to the forum...
Originally Posted past TrevorPhillips
SQL is meant to exist used in a Fix-Base fashion - that loop could be does in a unmarried command to SQL
UPDATE sometable Set up columnname='123' where {some status}
That is the correct way to interact with SQL.
-
Oct tertiary, 2013,02:05 PM #4
Re: How to use LOOP and SQL to update database
Originally Posted by szlamany
He asked for a loop... then I provided a loop.Trevor should give more than details.
-
Oct tertiary, 2013,07:42 PM #five
Thread Starter
Registered User
Re: How to utilise LOOP and SQL to update database
Thanks for the help. It seems I but placed the wrong variable in my code that'south why it only updates the final record.
-
October quaternary, 2013,09:37 AM #vi
Re: How to use LOOP and SQL to update database
How to utilize a loop and an update query to update all the records of a column?
Code:
Do While Not rs.Eof rs!<ColumnName> = value rs.MoveNext Loop rs.update
Lawmaking:
Exercise until rs.Eof rs!<ColumnName> = value rs.MoveNext Loop rs.update
Concluding edited by firoz.raj; Oct 4th, 2013 at 09:41 AM.
-
Oct 4th, 2013,09:47 AM #7
Re: How to use LOOP and SQL to update database
Originally Posted past szlamany
Originally Posted by firoz.raj
-tg
-
October 4th, 2013,06:38 PM #8
Re: How to utilise LOOP and SQL to update database
Originally Posted by szlamany
SQL-DML-statements can be useful (eastward.yard. as you said, when yous want to update
ColumnValues with a constant Expression beyond multiple records) - but information technology
is by no means the but "correct way".I see a whole lot of postings hither on the forum, which are fiddling (and failing) with exactly that -
composing (concatenating) right SQL-DML-statements.At that place's quite a lot of things i tin practise incorrect in specifying the correctly formatted value-expression
(quotes or non quotes, quotes within string-values... then correctly formatted appointment-values ... or the
correctly hex-encoded formats for Blob-values, which can differ from DB to DB).With the above in mind, I'd personally like when the inexperienced Users of ADO would be
encouraged by "The DB-Pros" hither, to work "through the Recordset" a bit more.In that location'due south non much which can go wrong with datatypes and stuff - SQL-injection would be
no problem too - and the usage is quite error-free and simple - it'due south only a matter of opening
the Recordset with the right parameters beforehand.Recordsets are quite similar in many regards to Control-Objects - and they don't even
require the definition of an SQL-DML-statement beforehand.Under the hood of an Rs.Update or Rs.UpdateBatch method, there'south (in the end) likewise a
construction of ane (or many) SQL-DML-statements in the stop, it'southward just hidden from the
user.Olaf
-
October fourth, 2013,07:04 PM #9
Re: How to use LOOP and SQL to update database
Cheers for your posting - this thread should have been marked airtight already as the OP - in mail service #five - their 2nd post on the forum - said they figured out what the issue was.
We were all given very petty info to get on - I fabricated a rash statement about "iterating" and "looping"...
I certainly didn't want to give someone a push into using hardcoded sql statements - I'm a 100% sproc user anyway - oasis't written an inline t-sql statement in 12 years...
@tg - I've been doing web apps for a couple of years now - and the re-querying you speak of I consider an important function of the "customer" knowing the "server" did the save properly. Fits nicely into my ajax-web-method handshakes...
Source: https://www.vbforums.com/showthread.php?736959-How-to-use-LOOP-and-SQL-to-update-database
0 Response to "Update Sql in Vb While in a Read Loop"
إرسال تعليق