0% found this document useful (0 votes)
62 views2 pages

Ms Access: "Provider Microsoft - Jet.Oledb.4.0Datasource D:/Mydata - MDB "

The document discusses connecting to and querying an Access database from VB.NET. It includes code to open connections to Access databases using ODBC and OleDb, execute queries to select and insert data, and populate data into a ListView. It also includes code to open an Access database using DAO and provide a password.

Uploaded by

Nanda Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views2 pages

Ms Access: "Provider Microsoft - Jet.Oledb.4.0Datasource D:/Mydata - MDB "

The document discusses connecting to and querying an Access database from VB.NET. It includes code to open connections to Access databases using ODBC and OleDb, execute queries to select and insert data, and populate data into a ListView. It also includes code to open an Access database using DAO and provide a password.

Uploaded by

Nanda Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

MS Access

Imports System.Data.Odbc


Dim con As New OdbcConnection("DSN=yoh;")

Dim cmd As New OdbcCommand

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

Imports System.Data.Oledb


Dim con As New
OledbConnection("Provider=microsoft.Jet.oledb.4.0DataSource=D:\mydata.mdb;")

Dim cmd As New OledbCommand

Public var1 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('" + var1 + "')"
cmd.ExecuteNonQuery()

End Sub

Collapse | Copy Code
Grabs data from a table and posts it into a ListView
Dim Table_ As String = "Table1"
Dim query As String = "SELECT * FROM " & Table_
Dim MDBConnString_ As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=TestDatabase.mdb;"
Dim ds As New DataSet
Dim cnn As OleDbConnection = New OleDbConnection(MDBConnString_)
cnn.Open()
Dim cmd As New OleDbCommand(query, cnn)
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, Table_)
cnn.Close()
Dim t1 As DataTable = ds.Tables(Table_)
Dim row As DataRow
Dim Item(2) As String
For Each row In t1.Rows
Item(0) = row(0)
Item(1) = row(1)
Dim NextListItem As New ListViewItem(Item)
ListView1.Items.Add(NextListItem)
Next
Dim sDBPassword as String
Dim oDBEngine As DAO.DBEngine
Dim oDB As DAO.Database

sDBPassword = "Mypassword" 'database password
oDBEngine = oAccess.DBEngine
oDB = oDBEngine.OpenDatabase(Name:=sDBPath, _
Options:=False, _
ReadOnly:=False, _
Connect:=";PWD=" & sDBPassword)
oAccess.OpenCurrentDatabase(filepath:=sDBPath, _
Exclusive:=False)
oDB.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDB)
oDB = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDBEngine)
oDBEngine = Nothing

You might also like