hey ppz! im havin problems wiv my code on vb.net! it dopesnt recognise the "ADODB connection()"-it says its not defined?? i have added the data adapter and connection, so why doesnt it work???

Imports System.IO
Public Class frmClients
    Inherits System.Windows.Forms.Form
    Dim CN As New ADODB.Connection()
    Dim RS As New ADODB.Recordset()

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

Dani AI

Generated

The ADODB "not defined" message usually means the project is missing the COM ADO reference or the code is mixing legacy VB6-style ADODB objects with VB.NET without the proper interop. The editor-only #Region has no effect on compilation, so 's suggestion to move declarations for that reason is incorrect — class-level declarations simply must live inside the class scope (placement before/after a region doesn't change visibility).

Two workable paths were suggested in the thread. Following 's advice, adding the COM reference "Microsoft ActiveX Data Objects" will make ADODB types available (Visual Studio will generate an interop assembly). That approach keeps legacy ADODB code but adds COM complexity and potential runtime/environment issues. The modern, recommended path — shown in spirit by and — is to use ADO.NET (OleDb or SqlClient): managed types, Using blocks, parameterized commands and DataReaders/DataAdapters avoid COM interop and are easier to maintain.

Minimal ADO.NET pattern (Access via ACE) — uses managed objects and parameterized queries, and avoids ADODB entirely:

Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data\MyDb.accdb;"
Using cn As New System.Data.OleDb.OleDbConnection(connString)
    Using cmd As New System.Data.OleDb.OleDbCommand("SELECT Name FROM Clients WHERE ID = ?", cn)
        cmd.Parameters.AddWithValue("?", 1)
        cn.Open()
        Using rdr As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader()
            If rdr.Read() Then
                txtName.Text = rdr("Name").ToString()
            End If
        End Using
    End Using
End Using

Quick checklist: confirm the References (COM) entry if ADODB is intended; add Imports ADODB or fully qualify names after adding the reference; prefer ADO.NET for new code; be aware Jet (OLEDB 4.0) is 32-bit only — build the project for x86 or use the ACE provider on 64-bit systems; always use Using blocks and parameterized queries for safety and reliability.

hey ppz! im havin problems wiv my code on vb.net! it dopesnt recognise the "ADODB connection()"-it says its not defined?? i have added the data adapter and connection, so why doesnt it work???

Imports System.IO
Public Class frmClients
    Inherits System.Windows.Forms.Form
    Dim CN As New ADODB.Connection()
    Dim RS As New ADODB.Recordset()

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

You should not make your declarations before the:
#Region " Windows Form Designer generated code "

Make all declarations after this code block. Also, you will need to add your imports statements at the very top:

Imports System()
Imports System.Data()
Imports System.Data.Oledb()

hey ppz! im havin problems wiv my code on vb.net! it dopesnt recognise the "ADODB connection()"-it says its not defined?? i have added the data adapter and connection, so why doesnt it work???

Imports System.IO
Public Class frmClients
    Inherits System.Windows.Forms.Form
    Dim CN As New ADODB.Connection()
    Dim RS As New ADODB.Recordset()

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

Well..What i can say is..
i'm not really good in Visual basic.net.but i'm doing on a project required to link database to my project. I'm using adodb connection.
Firstly,please check if you've added ADODB to your Reference ?
(if you've not or you're unsure.. double click on "Reference" on the Solution Explorer- check if you've "adodb"..if not right click on "Reference" .."Add Reference".Search for adodb and click select.)
If you've done the first part.. check this...

Imports System.Data.OleDb
Public Class frmClients

if you still have the problem pls let me know..i will try to help you..

hey ppz! im havin problems wiv my code on vb.net! it dopesnt recognise the "ADODB connection()"-it says its not defined?? i have added the data adapter and connection, so why doesnt it work???

Imports System.IO
Public Class frmClients
    Inherits System.Windows.Forms.Form
    Dim CN As New ADODB.Connection()
    Dim RS As New ADODB.Recordset()

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

em how's it?

Use MS Jet4 and then bound the fields using text and source data on the text boxes properties, this is fir each text box used

Hi,


Try this code. For MS access, change accordingly.

Purpose :To retrieve data from the database using Data Reader and Data Commands. When this code is executed, the data in a database is displayed in two textbox controls.

Preparation:

Design a form using .NET environment and place two textbox controls on a form.
Design and create a table using SQL Server 2000.

Name the Database as FinAccounting.
Name the Table as AccountsTable.
Name the form as Form1
Name the controls on the form as Textbox1 and Textbox2.

Tasks:

1. Establish the connection with the Database using Connection object.
2. Execute the command.
3. The data will be read by the Datareader object and the contents of the first record is displayed in the textboxes.

Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim str_sql_user_select As String = “SELECT * FROM AccountsTable
Dim str_connection As String = “Data Source=VSDOTNET;Integrated Security=SSPI;Initial Catalog=FinAccounting
Dim mycon As SqlConnection
Dim comUserSelect As SqlCommand
Dim myreader As SqlDataReader

Private Sub Form1_Load(ByVal sender As Object, ByVal e As system.EventArgs) Handles
MyBase.Load
mycon = New SqlConnection(str_connection)
‘Instantiate the commands
comUserSelect = New SqlCommand(str_sql_user_select, mycon)
TextBox1.Text = “ “
TextBox2.Text = “ “
mycon.Open()
myreader = comUserSelect.ExecuteReader
If (myreader.Read = True) Then
TextBox1.Text = myreader(0)
TextBox2.Text = myreader(1)
Else
MsgBox(“You have reached eof)
End If
End Sub
End Class


Regards
Bhar
Books fro programmers

Here's what I did

myPath = "c:\Table.mdb"
myQuery = "select * from table"

Public Function Return_Access(ByVal myQuery As String, ByVal myPath As String) As DataSet
Dim myConnStr As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + myPath
Dim myConn As New OleDb.OleDbConnection(myConnStr)
Dim myAdapt As New OleDb.OleDbDataAdapter(myQuery, myConn)

Try
myConn.Open()
Dim myReader As New DataSet
myAdapt.Fill(myReader)
Return myReader
myConn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Function

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.