Vb. NET Learning Notes (2)

Source: Internet
Author: User
Tags access database

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.