SEB’s VB.NET Guide
2.Initialise database variables3.Fill the dataset with the contents of the database table4.Populate the labels
1.Establish the connection
objDA = New OleDbDataAdapter(“Select * from Data”, _ “Provider=Microsoft.Jet.OLEDB.4.0;Password=;” _ & “User ID=Admin;Data Source =” & _ Application.StartupPath & “\Dbase.mdb”)
•
ObjDA is the OleDbDataAdapter variable previously declared
•
This is all one statement which has overflowed across several lines – when this occurs ina program, underscores are required to indicate that where one line continues on toanother.
•
There are two strings passed in through the parenthasis:
“Select * from Data”
This is an SQL statement which extracts the required data from the database.
* means anything / everything (ie: all fields)
Data
is the name of the table in the database being accessed
The SQL statement can extract more specific data or extract the datain a specified order (sorted)
“Provider=Microsoft.Jet.OLEDB.4.0;Password=; User ID=Admin;DataSource =” & Application.StartupPath & “\Dbase.mdb”)
Note: The & at the beginning of line 3 was used only rejoin the string where is had been split.
This statement specifies the type of database being accessed
Application.StartupPath
is a relative path (to the projects BINfile)
Dbase
is the name of the database being accessed
2.Initialise database variables
objDS = New Data.DataSet()objCB = New OleDbCommandBuilder(objDA)
•
objDS
and
ObjCB
are variables previously declared to store required data components
3.Fill the dataset with the contents of the database table
objDA.Fill(objDS, “Data”)
•
Using the
Fill
property of
objDA
the dataset is filled with the contents of the table
•
Data
refers to the database table.
Page 2 of 3
Add a Comment