May 1, 2010 at 2:45 am
Hi
I wrote a VB6 program using SQL-DMO. Everything works fine except I don't know how to get the real result of an UPDATE SQL Statement.
For exemple:
UPDATE MY_TABLE SET CLt_Name=new_name where Clt_ID=myID
Whatever the myID value (existing in my DB or not) this SQL command run from VB60 (ExecuteWithMessage) will produce the same result: No error and number of row is zero.
How can I detect an error if myID is wrong??
May 1, 2010 at 6:28 am
yeah from a SQL perspective, an update that affects zero rows is not an "error", but from your perspective it's a logical error, as you expected at least one row to be fiddled with. probably want to check the rows effected with @@rowcount to be sure whether your statement affected anything; are you doing that now?
show us your real code you are using; it might be something minor in your vb6 code you are overlooking, like assigning a value to a variable, or not substituting a value into your UPDATE statement.
Lowell
May 3, 2010 at 1:58 am
Hi
Thank you for this reply.
Actually my VB6 program looks that:
Dim oSQLServer As New SQLDMO.SQLServer
Dim oDatabase As New SQLDMO.Database
Dim oTheResults As SQLDMO.QueryResults
.../...
Public Function myQuery(r As String) As Integer
Dim ret As Integer
Err.Number = 0
On Error GoTo EndMyQuery
myQuery = 1 'set error by default
Set oTheResults = oDatabase.ExecuteWithResults(r)
myQuery = 0 'ok
EndMyQuery:
End Function
.../...
req = "UPDATE " + T_LEAFS + " SET leaf_name='" + name2 + "' WHERE leaf_key='" + myKey + "'"
If (myQuery(req) <> 0) Then SQLError "Rename Node/Leaf"
'Debug.Print CStr(oTheResults.ROWS)
oTheResults.ROWS is always equals to 0. Whatever the condition "leaf_key=x" is true or not.
So I can't know when the UPDATE operation is actually done.
Do you think the ExecuteWithResultsAndMessages instructions will give me the missing information?
The last solution could be the use of IF EXISTS (...) instruction
Thank you
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply