| | |
SQL Query recordcount = -1 in VB, 32 in Query Analyzer
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 9
Reputation:
Solved Threads: 0
I have SQL code in my VB6 project for select, insert, and truncate. For example:
LINE_IMP_VIEW is a view over a table. You could use the same SQL statement above on the table itself. This statement works fine. The TRUNCATE TABLE and INSERT INTO statements work fine as well, "TRUNCATE TABLE LINE_IMP" and "INSERT INTO LINE_IMP (fields) VALUES (list)".
This is the SQL I'm having problems with:
And later in the procedure:
This gives the correct string:
I created the query above in SQL Analyzer. It gives me the proper results there, 32 records. This is MILESTONE_IMP_VIEW:
When I use the query with the view in VB, the recordcount is coming back -1. Is this just too complicated for ADO to handle?
I'm using this:
Any help is GREATLY appreciated!
teresa
VB Syntax (Toggle Plain Text)
strSQL = "SELECT CASE_IDENTIFIER" & vbCrLf _ & " ,DOCUMENT_TYPE" & vbCrLf _ & " ,DOCUMENT_NUMBER" & vbCrLf _ & " ,CASE_LINE_NUMBER" & vbCrLf _ & " ,DELETION_INDICATOR" & vbCrLf _ & " ,MASL" & vbCrLf _ & " ,MDE_CODE" & vbCrLf _ & " ,GENERIC_CODE" & vbCrLf _ & " ,CASE_LINE_ITEM_QUANTITY" & vbCrLf _ & " ,TOTAL_LINE_VALUE_AMOUNT" & vbCrLf _ & " ,CASE_LINE_ITEM_DESCRIPTION " & vbCrLf _ & " FROM LINE_IMP_VIEW " & vbCrLf _ & " ORDER BY CASE_IDENTIFIER"
LINE_IMP_VIEW is a view over a table. You could use the same SQL statement above on the table itself. This statement works fine. The TRUNCATE TABLE and INSERT INTO statements work fine as well, "TRUNCATE TABLE LINE_IMP" and "INSERT INTO LINE_IMP (fields) VALUES (list)".
This is the SQL I'm having problems with:
VB Syntax (Toggle Plain Text)
strSQL = "SELECT CASE_IDENTIFIER" & vbCrLf _ & " ,DOCUMENT_NUMBER" & vbCrLf _ & " ,DOCUMENT_TYPE" & vbCrLf _ & " ,MILESTONE" & vbCrLf _ & " ,MILESTONE_DATE" & vbCrLf _ & " ,MILESTONE_DATE_TYPE" & vbCrLf _ & " ,MILESTONE_REMARKS" & vbCrLf _ & " FROM MILESTONE_IMP_VIEW" & vbCrLf strSQLWhere = " WHERE CASE_IDENTIFIER = '" strSQLCIin = " AND CASE_IDENTIFIER IN" & vbCrLf _ & " (SELECT CASE_IDENTIFIER" & vbCrLf _ & " FROM CASE_MASTER_TEMP)" strSQLandDN = " AND DOCUMENT_NUMBER = '" strSQLDNin = " AND DOCUMENT_NUMBER IN" & vbCrLf _ & " (SELECT DOCUMENT_NUMBER" & vbCrLf _ & " FROM CASE_MASTER_TEMP)" & vbCrLf
And later in the procedure:
VB Syntax (Toggle Plain Text)
strSQL = strSQL & "" _ & strSQLWhere & .masterVars(j).CASEIDENTIFIER & "'" & vbCrLf _ & strSQLCIin & vbCrLf _ & strSQLandDN & .mileVars(j).DOCNUM & "'" & vbCrLf _ & strSQLDNin
This gives the correct string:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
SELECT CASE_IDENTIFIER ,DOCUMENT_NUMBER ,DOCUMENT_TYPE ,MILESTONE ,MILESTONE_DATE ,MILESTONE_DATE_TYPE ,MILESTONE_REMARKS FROM MILESTONE_IMP_VIEW WHERE CASE_IDENTIFIER = 'A2-B-OBM' AND CASE_IDENTIFIER IN (SELECT CASE_IDENTIFIER FROM CASE_MASTER_TEMP) AND DOCUMENT_NUMBER = '000' AND DOCUMENT_NUMBER IN (SELECT DOCUMENT_NUMBER FROM CASE_MASTER_TEMP)
I created the query above in SQL Analyzer. It gives me the proper results there, 32 records. This is MILESTONE_IMP_VIEW:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
SELECT CASE_IDENTIFIER AS CASE_IDENTIFIER ,DOCUMENT_TYPE AS DOCUMENT_TYPE ,DOCUMENT_NUMBER AS DOCUMENT_NUMBER ,MILESTONE AS MILESTONE ,MILESTONE_DATE_TYPE AS MILESTONE_DATE_TYPE ,MILESTONE_DATE AS MILESTONE_DATE ,MILESTONE_REMARKS AS MILESTONE_REMARKS FROM CASE_MILESTONE_TEMP WHERE CASE_IDENTIFIER IN (SELECT CASE_IDENTIFIER FROM CASE_MASTER_TEMP WHERE (CASE_MASTER_STATUS_CODE = 'N' OR CASE_MASTER_STATUS_CODE = 'P') AND IMPLEMENTING_AGENCY = 'B' AND (DOCUMENT_TYPE = 'AMD' OR DOCUMENT_TYPE = 'LOA') AND CASE_VERSION_STATUS_CODE = 'I')
When I use the query with the view in VB, the recordcount is coming back -1. Is this just too complicated for ADO to handle?
I'm using this:
VB Syntax (Toggle Plain Text)
Public cn As New ADODB.Connection Public cmd As New ADODB.Command Public rs As New ADODB.Recordset cmd.CommandText = qry cmd.CommandType = adCmdText Set rs = cmd.Execute
Any help is GREATLY appreciated!
teresa
•
•
Join Date: Oct 2008
Posts: 9
Reputation:
Solved Threads: 0
I found the solution:
http://www.experts-exchange.com/Web_..._20809772.html
All you have to do is scroll all the way to the bottom of that page to see the answers.
I changed this
to this:
That was all.
teresa
http://www.experts-exchange.com/Web_..._20809772.html
All you have to do is scroll all the way to the bottom of that page to see the answers.
I changed this
VB Syntax (Toggle Plain Text)
cmd.CommandText = qry cmd.CommandType = adCmdText Set rs = cmd.Execute
to this:
VB Syntax (Toggle Plain Text)
Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open qry, cn, adOpenKeyset, adLockOptimistic
That was all.
teresa
Last edited by pixelmeow; Oct 29th, 2008 at 3:25 pm. Reason: how to see the answer on the web page
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How I Creat Shortcut of My Project On Desktop
- Next Thread: Limiting the Decimal Places and point
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





