The database information is read into the memory array

Source: Internet
Author: User
Data | database | Arrays In general, it is easier to process small amounts of data if you read the data into a simple memory array. The following methods provide a Ado.net object to load information from the database to an array, and the array can be expanded arbitrarily.

Enter the following code in the header of the default form:
Imports System.Data.OleDb
In the Click event of the button:
Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim MyConn as OleDbConnection
Dim myCMD as OleDbCommand
Dim myreader as OleDbDataReader
Dim Myconnstr as String
Dim myarray (0) as String
Dim I as Integer

Myconnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=jlgl.mdb"
myconn = New OleDbConnection (myconnstr)
myCMD = New OleDbCommand ()
Mycmd.commandtype = CommandType.Text
Mycmd.commandtext = "SELECT * FROM JXB"
Mycmd.connection = myconn
MyConn.Open ()
myreader = Mycmd.executereader
Do While Myreader.read
MyArray (i) = myreader! Factory number
TextBox1.Text = TextBox1.Text & MyArray (i) & VbCrLf
ReDim Preserve myarray (UBound (myarray) + 1)
i + 1
Loop
Label1.Text = i ' I for the number of record bars

Myconn.close ()

End Sub



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.