ralph
1/16/2012 8:36:00 PM
On Mon, 16 Jan 2012 13:24:14 -0600, Jim Archer <nospam@nothanx.com>
wrote:
>Hi all. I'd post this on the VB6 ADO or VB6 database groups, but it seems dead
>over there. I've also done quite a bit of Googling about this, but strangely
>only found one post way back in 2004, with no replies and he was using C++.
>
>Anyway, while working in ADO recently (am new but learning fast), I ran into
>trouble trying to update a text field with more characters than the DefinedSize
>(using rs.Fields("FieldName").Value =). Trying to edit other fields after that
>(same recordset) causes the "Update or CancelUpdate without AddNew or Edit"
>error, and of course it prevents rs.Update from working as well. The thing is
>though, if my program tries to update a numeric field with text, for example, I
>get an error, but it allows other fields to be updated just fine and allows
>rs.Update to happen.
>
>Now, I could put in a check to see if the field is text, check that the string
>is greater than the DefinedSize, then truncate the text to the DefinedSize, but
>I'd really like to prevent those steps since I'm updating 100+ fields per second
>from date coming in from multiple threads and I'm mostly testing right now. I
>just want it to "ignore and continue" like "On Error Resume Next" would in VB
>itself instead of totally breaking.
>
>Has anyone ran into this before? And is there maybe a way I can tell ADO to
>just ignore the error and continue to allow updates of other fields without
>having to re-open the recordset?
You might try not using the Update method.
Background: With Update ADO constructs, behind the scenes, its best
guess as to what an Update Query would look like (from the original
'fetch' query), and tries to track what has been changed so it knows
what to "update" when called upon. When it gets an error ADO (at the
top-level) doesn't really care what happened, where, or why - it just
knows the query is 'bad'.
So you might create your own separate update queries, eg. put the
troublesone one in one query, run, catch error, and repair or skip,
and then go on to update the rest.
You didn't mention the database but you could make them SPs so they
are a bit quicker. (ADO's construct is semi pre-parsed.)
Frankly I'd fix the original problem now. You will have to address the
issue of bad data sooner or later.
A simple Len and Mid call to truncate a string shouldn't have that
much impact (I think <g>) on over-all performance. Or if "data string
is too long" is a very frequent occurrence then just truncate all
incoming strings. You will have to test on your data.
-ralph