HI

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
conn.Open()

End Sub

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

End Sub

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

End Function

Sub moddb(ByVal t As String)
adcomm(t)
comm.ExecuteNonQuery()

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

Thnx

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.

Exapmle..

Dim M_connstring as string
Public Property ConnString as string
 Get
            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
ObjCls.ConnString=textbox.text

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
        Get
            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
        Main.Show()
        MsgBox(CS)

Hi,

Try this:

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

conn.Open()
This article has been dead for over six months. Start a new discussion instead.