01.
Function
CheckBoxListDataTable()
02.
Dim
objConn
As
OleDbConnection
03.
Dim
dtAdapter
As
OleDbDataAdapter
04.
Dim
dt
As
New
DataTable
05.
06.
Dim
strConnString
As
String
07.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& _
08.
Server.MapPath(
"database/mydatabase.mdb"
)&
";"
09.
objConn =
New
OleDbConnection(strConnString)
10.
objConn.Open()
11.
12.
Dim
strSQL
As
String
13.
strSQL =
"SELECT * FROM country"
14.
15.
dtAdapter =
New
OleDbDataAdapter(strSQL, objConn)
16.
dtAdapter.Fill(dt)
17.
18.
dtAdapter =
Nothing
19.
objConn.Close()
20.
objConn =
Nothing
21.
22.
23.
With
Me
.myCBoxList1
24.
.DataSource = dt
25.
.DataTextField =
"CountryName"
26.
.DataValueField =
"CountryCode"
27.
.DataBind()
28.
End
With
29.
30.
31.
myCBoxList1.SelectedIndex = myCBoxList1.Items.IndexOf(myCBoxList1.Items.FindByValue(
"TH"
))
32.