SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Retreive an error for an UPDATE SQL Statement


Retreive an error for an UPDATE SQL Statement

Author
Message
animho
animho
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 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??
Lowell
Lowell
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27958 Visits: 39921
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

animho
animho
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search