Results 1 to 2 of 2

Thread: How to open local Access 2000 table into ADODB.RecordSet?

  1. #1

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    211

    How to open local Access 2000 table into ADODB.RecordSet?

    I am using this helper function to open my local helper table in ADODB.RecordSet with VB.NET.

    Code:
    Public Sub OpenRecordSetDynamic(ByRef recordSet As ADODB.Recordset, ByVal sql As String, ByRef dbConn As ADODB.Connection)
            Try
                recordSet.Open(sql, dbConn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)
            Catch ex As Exception
                Dim funcName As String = System.Reflection.MethodInfo.GetCurrentMethod().Name
                Console.WriteLine(funcName & ": " & ex.Message & ", Source: " & ex.Source & ", StackTrace: " & ex.StackTrace)
            End Try
        End Sub
    where sql eguals:

    Code:
    DELETE FROM MyTable;
    I get an exception that the object is closed, i.e in this case, it doesn't open the table.

    Note: by local table i mean a table created in Access 2000.

    What should I do in VB.NET?
    And what do i do wrong?
    Last edited by kutlesh; Mar 5th, 2019 at 03:38 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to open local Access 2000 table into ADODB.RecordSet?

    Quote Originally Posted by kutlesh View Post
    What should I do in VB.NET?
    And what do i do wrong?
    You should use ADO.NET.
    And you're using ADODB.

    As the name suggests, ADO.NET is a data access technology that was developed specifically for .NET and that is what you should use. If you're using an Access database then you should use members of the System.Data.OleDb namespace, e.g. OleDbConnection. You can call ExecuteReader on an OleDbCommand if you want to access data in a forward-only, read-only manner, e.g. to process data as you read it. If you want random access to the result set of a query, call Fill on an OleDbDataAdapter to populate a DataTable. You edit that data if you wish, then save the changes back to the database by calling Update on the same adapter.

    I would suggest that you follow the Database FAQ link in my signature below and check out some of the .NET resources there, including my own ADO.NET code examples.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

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