The last time, I showed you how to connect ms access and vb.net using ODBC. This time we will use OLEDB to connect the two.
The procedure is similar, so you may want to check this for a more complete tutorial.
I supposed you still have the files from the previous tutorial. So I’m going straight to the point.
What needs to be changed is the connection string and the name space.
The namespace this time is:
The connection string will be:
Remember to change the data source to the actual path where your database is. Followed by the filename of your database. You can use either .mdb or .accdb for this.
Finally, change all the odbc that you see to oledb.
The whole of your code in your parent class will look something like this:
Imports System.Data.OleDb Public Class Class1 Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersWernDocumentsDatabase1.accdb;") Dim cmd As New OleDbCommand Public neym As String Public Sub New() con.Open() cmd.Connection = con cmd.CommandText = "SELECT * FROM table1" End Sub Public Sub creates() cmd.CommandText = "INSERT INTO table1(Neyms) VALUES('" + neym + "')" cmd.ExecuteNonQuery() End Sub End Class
That’s it, don’t forget to declare an object of the parent class that you created on your main form:
dim parent as new class1
Where class1 is the name of the class, and parent is the object name that you want. You can change it to whichever you want. But the class name always depends to what class name you have inputted a while ago.