Dear Friends, I am new to Visual basic 2005 as I have used VB6 till now. I wish to do a database application using Microsoft Access 2003 and Visual basic 2005. I am very happy, if any one could give the step by step instruction to connect Access, insert, delete, update records and so on. Thanks in advance.

DAO and ADO have been replaced by ADO.NET, and it's a significant change, but easy to adjust to.

If you're connecting to Access, the connection string you've probably been using in VB6 is more than likely sufficient for VB2005. The objects you're going to want to look at would be the OleDbConnection to replace your VB6 ADODB.Connection object. This object is going to be used no matter what you are doing.

There's no one-to-one replacement for the ADODB.Recordset with ADO.NET. If you just want to execute a statement against the database without returning results (or perhaps you just want a single, one field result), look at using the OleDbCommand. If you want the contents of a query complete with multiple rows and/or columns, you have the option of using an OleDbDataReader (along with the command object) to get a forward-only data stream from the open connection, or you can look at using an OleDbDataAdapter to put the results into a DataTable (or a DataTable within a DataSet).

For inserting or updating data in the database, just construct your own Insert/Update statements and execute them using the aforementioned OleDbCommand object.

Incidentally, these "OleDb" objects are all part of a family of objects that are optimized for the particular type of connection you're using. If you were using an ODBC data source instead of OLEDB, you would use objects such as OdbcDataConnection, OdbcCommand, etc. Similarly, if you were using SQL Server as your data source, you could use the SqlConnection and SqlCommand objects. These are built into .NET in the System.Data.OleDb, System.Data.Odbc, and System.Data.SqlClient namespaces. There are other providers available as well (MySQL, Oracle, etc.), though they're not built into .NET by default (the existing objects will work against these database platforms).

This is an example of VB code to retrieve information from a database using OleDb.

Imports System.Data
Imports System.Data.OleDb

Module Module1

    Sub Main()

        'establish connection, adapter, and datatable objects
        Dim connection As OleDbConnection = New OleDbConnection("your_connection_string")
        Dim sql As String = "Select * From YourTable"
        Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(sql, connection)
        Dim dt As DataTable = New DataTable()

        'fill datatable with results of sql statement
        adapter.Fill(dt)

        'process each row of data 
        For Each dr As DataRow In dt.Rows
            Dim fieldValue As String = dr("your_field_1").ToString()
        Next

        'release resources
        dt.Dispose()
        adapter.Dispose()
        connection.Dispose()

    End Sub

End Module

Check MSDN and other online resources for more information on using these objects.

commented: Great. +7

Thank you So much Mr.Thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.