Re: VB6 - ADODB - Strange behavior between IDE & EXE
- From: "SME" <smelchuri@xxxxxxxxxxx>
- Date: Thu, 28 Aug 2008 12:36:21 -0400
In the article you provided, it mentions that RecordCount may return -1 for unsupported CursorType. OK, taking that I may not get correct value for the RecordCount, I can test for EOF. However, this CursorType usage had been working for years, particularly with Access and Sybase ASE, on Windows 2000 and XP. I had been copying the same code from other working programs.
But what about "Source"?. Why it is changing? It appears that the rs object itself is now reflecting some other object than that I set in the given LostFocus event. Do you mean to say that if I test for EOF the problem would be solved?
ThanQ...
"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx> wrote in message news:uxl0LgSCJHA.2272@xxxxxxxxxxxxxxxxxxxxxxx
.
"SME" <smelchuri@xxxxxxxxxxx> wrote in message news:OGV9rUSCJHA.1628@xxxxxxxxxxxxxxxxxxxxxxxHi,
I am getting different behavior between running my code in VB6 IDE and after creating an EXE.
In the LostFocus code given below, I have two messages being displayed, namely, Msg-1 and Msg-2.
When I run it in IDE, I get same messages for Msg-1 and Msg-2.
But when I create an EXE and run it, Msg-1 shows RecordCount = 1 and .Source as what was set and Msg-2 shows RecordCount = 198 and .Source = SELECT ... FROM Client. Yes I do have table named Client with 198 rows in my database and I do use this SELECT ... FROM Client in a GotFocus event after finishing with the given LostFocus event But how can this happen?
The database I am using is Sybase ASE 15.0.2
I open the ADODB connection in the Form_Load as follows:
Set oConn = New ADODB.Connection
Set rs = New ADODB.Recordset
'make connection with DBMS
With oConn
.ConnectionString = "DSN=ASE15_MY_DB;UID=sa"
.CursorLocation = adUseClient
.Mode = adModeReadWrite
.Open
If .State = adStateOpen Then
.Execute "USE MY_DB", , adCmdText
End If
End With
Then in a LostFocus event, I have the following code:
With rs
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = oConn
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Source = "SELECT ... FROM Project WHERE ProjectCode = '" + txtProjectCode.Text + "'"
.Open
If .State = adStateOpen And .RecordCount > 0 Then
MsgBox "Msg-1: The RecodCount = " + Format$(.RecordCount, "#") + " .Source = " + .Source
iAns = MsgBox("The entered project code already exists." + vbNewLine + vbNewLine + "Do you want to add a NEW INSTANCE of the same project?", vbYesNo + vbQuestion, "Entering Project Code")
If iAns = vbYes Then
MsgBox "Msg-2: The RecodCount = " + Format$(.RecordCount, "#") + " .Source = " + .Source
--- some more code ---
EndIf 'end of iAns = vbYes
EndIf 'end of .State = adStateOpen And .RecordCount > 0
End With
Your cursorType does not support RecordCount. See this link:
http://support.microsoft.com/kb/194973
If you need to know if there are any records in the recordset, use the EOF property of the recordset. If you need the number of records, it might be more reliable to use the COUNT sql function. Otherwise, use a cursorType that supports RecordCount.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
- References:
- Prev by Date: VB6 - ADODB - Strange behavior between IDE & EXE
- Next by Date: ADODB Connection in Windows Vista: Password missing in ConnectionString
- Previous by thread: VB6 - ADODB - Strange behavior between IDE & EXE
- Next by thread: Re: VB6 - ADODB - Strange behavior between IDE & EXE
- Index(es):
Relevant Pages
|