Create a new Visual Basic Project
after creating this project a new form will appear after that you need to add a Component press CTRL+T to open Component
A dialog will appear the Check Microsoft ADO data Control 6.0 (OLEDB) press apply then Ok, on the ToolBox a new control will be added double click it then you are ready to browse for a new connection
The control which is highlighted or selected is the one who we added from the components after that select the control the right click the press property if you will do that procedure a dialog will appear that will show the properties of that control then press build,pressing the build button will give you a question or choices which provider you would like yo use for MS-Access it is Microsoft Jet 4.0 OLE DB provider then press next
After pressing next you need to browse for your database on where it is located press the button on the right part with a label of "..." then you need to locate your database
after specifying your database press ok then a connection string will appear Copy the Connection string then press apply and ok then where Done with the browsing of the connection String
After Browsing for a Connection add a Module on your project Press the option at the top of your vb window with a Project caption then add a Module, a module will be added on your project explorer then double click your module for our coding
Public con As New ADODB.Connection
Sub init_con()
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\testdb\Data\db_SADStore.mdb;Persist Security Info=False"
con.Open
End Sub
Sub init_con()
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\testdb\Data\db_SADStore.mdb;Persist Security Info=False"
con.Open
End Sub
add this code on your module change the value of con.connection from the connectionstring that you already added
First declaration is a varialble name con with a Data type of ADODB Connection with this variable there is a keyword Public meaning all of the forms modules that you will can access this variable, a function is created with name of init_con this function initializes the connection and open it for accessing the specified database.
to test your code open Form1 the double click it the then call the function init_con then your code should run smoothly
--- happy coding
Walang komento:
Mag-post ng isang Komento