Results 1 to 2 of 2

Thread: Adodb converting to Sqlite issue

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Uk
    Posts
    157

    Adodb converting to Sqlite issue

    I'm moving my database from access to sqlite - however i'm having issues with converting the following:

    Code:
                  Dim connectStr = (Strings.DBConnectstrings)
            Dim strm As New ADODB.Stream
            Dim con As New ADODB.Connection
            Dim rs As New ADODB.Recordset
            Dim stmt As String = New String("")
            stmt = "SELECT *  FROM exam WHERE [Section] = '" & section & "'"
    
            Try
                con.Open(connectStr)
                '  rs = con.Execute(stmt)
                rs.Open(stmt, con, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, &H1)
                ' con.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    I dont know what sqlite statements to use to replace the ADODB recordset

    So far:
    Code:
                  Dim con As New SQLiteConnection(Strings.DBConnectstrings.ToString)
            Dim rs As New ADODB.Recordset
            Dim sql As String
            Sql = "SELECT *  FROM exam WHERE [Section] = '" & section & "'"
            Dim adapter As New SQLiteDataAdapter(sql, con)
            Dim dt As New DataTable("exam")
            Try
                adapter.Fill(dt)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    However i get an error
    System.Runtime.InteropServices.COMException (0x800A0E78): Operation is not allowed when the object is closed.
    at ADODB.RecordsetClass.Move(Int32 NumRecords, Object Start)
    Can anyone point me in the right direction

    Full sub:
    Code:
        Private Sub getDbRecord(ByVal section As String)
    
            Dim connectStr = (Strings.DBConnectstrings)
            Dim strm As New ADODB.Stream
            Dim con As New ADODB.Connection
            Dim rs As New ADODB.Recordset
            Dim stmt As String = New String("")
            stmt = "SELECT *  FROM exam WHERE [Section] = '" & section & "'"
    
            Try
                con.Open(connectStr)
                '  rs = con.Execute(stmt)
                rs.Open(stmt, con, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, &H1)
                ' con.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    
            Dim i
            Dim randList = getRandList(QnosEachSection)
            ' MsgBox(randList.Count)
            For i = 0 To randList.count - 1
                Dim x = randList.Item(i)
    
                rs.Move(x)
                Dim question As Question = New Question
                question.section = rs.Fields().Item(1).Value
                question.question = rs.Fields().Item(2).Value
                question.option1 = rs.Fields().Item(3).Value
                question.option2 = rs.Fields().Item(4).Value
                question.option3 = rs.Fields().Item(5).Value
                question.option4 = rs.Fields().Item(6).Value
                question.answer = rs.Fields().Item(7).Value
                'Added for regs
                question.regulation = rs.Fields().Item(9).Value
                'added for attachment
                If rs.Fields(8).ActualSize > 0 Then
                    question.attachment = rs.Fields(8).Value
                    question.hasAttachment = True
                Else
                    question.hasAttachment = False
                End If
    
                qList.Add(question)
                '   MsgBox(question.ToString)
                rs.MoveFirst()
            Next
    
        End Sub
    Last edited by experience; Dec 10th, 2012 at 07:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width