Establishing a connection to an Access database
Main content Reference Http://hi.baidu.com/zengxingye "connecting Access databases in vb.net"
I set up a database called Database1.mdb, which has two columns of user, PSWD
First import the name space
Imports System.Data.oledb
Because the OLE DB class that we're going to use is defined in the name space.
Dim constr as String = "Provider=microsoft.jet.oledb.4.0;user ID =admin;password=;" Data Source = Database1.mdb "
' Define the connection string
Dim accessstr as String = "SELECT * FROM table1"
' Read the data from table 1
Dim Mycon as New OleDbConnection (CONSTR)
' Define Connection
Dim mycom as New OleDbCommand (ACCESSSTR, mycon)
' Define an Access command and use the defined Access command string and connection Mycon to make its arguments
Dim Myread as OleDbDataReader
' Define the reader
Mycon. Open ()
' Open connection
Myread = mycom. ExecuteReader
While Myread.read
Dim username as String = myread (0)
Dim password as String = Myread (1)
' Here to do other processing
End While
' Read the data in a loop, Myread.read is returned true if it has a readable record
Mycon. Close ()
' Connection closed
If the database is not encrypted the default access username is admin and the password is blank
Thanks to bug Two's home Zengxingye blog