Friday, August 19, 2011

record number in dataset

I found my first problem

my adodb.recordset was not configured to count the number of records correctly

of course there was 1000 solution on internet, but none was for visual basic net 2010
I finally found the good one!

here is my new code for the sql request:


    Function exesql( _
    ByVal oobjcon As ADODB.Connection, _
    ByVal dummy As ADODB.Recordset, _
    ByVal SQL01 As String)


        Dim cmd As New ADODB.Command()
        Dim aaa As String
        Dim count As Integer
        'On Error Resume Next
        Const adOpenStatic = 3
        Const adLockOptimistic = 3
        Const adOpenForwardOnly = 0


        ttag = New ADODB.Recordset
        ttag.CacheSize = 1
        ttag.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        ttag.CursorType = ADODB.CursorTypeEnum.adOpenStatic
        ttag.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic


        Try
            If logall = 1 Then
                fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " query:")
                fil02.writeline(SQL01)
            End If
            '=== caca3
            '=== ADODB.Recordset how many did we get? bug


            'objRecordset.Open source,actconn,cursortyp,locktyp,opt


            'ttag.Open(SQL01, oobjcon)
            'ttag.CacheSize = 1000
            'ttag = objcon.Execute(SQL01)


            ttag.Open(SQL01, objcon)


            'ttag.CacheSize = 1000
            'ttag.MoveLast()


            'count = ttag.Fields.Count
            count = ttag.RecordCount


            If logall = 1 Then
                fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " query done without error")
                fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " total count in recordset: " & count)
            End If
        Catch ex As Exception
            aaa = Err.Description
            l1 = "error in query"
            l2 = "query: " & SQL01
            l3 = "error: " & aaa
            l4 = "the program will now end"
            fbot.WriteLn(l1 & "<BR><br>" & l2 & "<BR><br>" & l3 & "<BR><br>" & l4 & "<BR><br>")


            If logall = 1 Then
                fil02.writeline("query:")
                fil02.writeline(SQL01)
                fil02.writeline(Err.Description)
            End If
        End Try
        'wscript.quit()
        '=== END PROGRAM 
        Return (ttag)
    End Function




No comments:

Post a Comment