can some one Help in my graduation project

im making database access connection this is my class

Imports System.Data.OleDb
Public Class DataBaseConn

Dim conn As New OleDbConnection
Dim comm As New OleDbCommand
Dim s As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\G-project Crab\GP\GP\Database1-2.mdb"

Sub adconn()
conn.ConnectionString = s

End Sub

Sub adcomm(ByVal t As String)
comm.Connection = conn
comm.CommandText = t

End Sub

Function seldb(ByVal t As String) As OleDbDataReader
Dim dr As OleDbDataReader
dr = comm.ExecuteReader
Return dr

End Function

Sub moddb(ByVal t As String)

End Sub
End Class


See the Code in red i want to select the source of the database from another Form that had a textbox contain the path of the database that been selected from i file dialoge my main issue is i dont know how to transfer data between Form and class


Recommended Answers

All 3 Replies

Write property in your class which sets or gets the Connection string. which should be public. and create the instance of this class in the form where you want to set the connection string from textbox and access the proprty and set it.


Dim M_connstring as string
Public Property ConnString as string
            ConnString = M_connstring 
        End Get
        Set(ByVal Value As String)
            M_connstring = Value
        End Set

In the form where u want to set this property

Dim objCls as new ClassName

Hope this helps you.

Didnt work i get message Connection String is not set

Here what i write in my class

Public Property ConnString() As String
            ConnString = M_connstring
        End Get
        Set(ByVal Value As String)
            M_connstring = Value
        End Set
    End Property

here is My Form

Dim objCls As New DataBaseConn
        Dim CS As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & TextBox1.Text

        objCls.ConnString = CS


Try this:

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\G-project Crab\GP\GP\Database1-2.mdb"

Be a part of the DaniWeb community

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