Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Retreive an error for an UPDATE SQL Statement Expand / Collapse
Author
Message
Posted Saturday, May 1, 2010 2:45 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 3, 2010 1:52 AM
Points: 2, Visits: 3
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??
Post #914216
Posted Saturday, May 1, 2010 6:28 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:40 PM
Points: 12,897, Visits: 32,105

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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #914226
Posted Monday, May 3, 2010 1:58 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, May 3, 2010 1:52 AM
Points: 2, Visits: 3
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
Post #914518
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse