<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.OleDb" %>
<script language="VB" runat="server">
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arrData() As String
'Create a connection string
Dim connString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("datatabase.mdb")
'Open a connection
Dim objConnection As OleDbConnection = New OleDbConnection(connString)
objConnection.Open()
'Create SQL string
Dim strSQL As String = "SELECT field1 FROM table1"
'Create a command object
Dim objCommand As OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)
'Get a datareader
Dim objDataReader As OleDbDataReader
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
'Loop
Dim i As Integer
i = 0
ReDim arrData(100)
While objDataReader.Read()
arrData(i) = objDataReader("field1")
i = i + 1
End While
Dim jLoop As Integer
For jLoop = 0 To i-1
Response.Write(arrData(jLoop) & "<br />")
Next
'Close the datareader/db connection
objDataReader.Close()
objConnection.Close()
End Sub
</script>
วันที่สร้าง : 21 เมษายน 2550 เวลา 12:18
จำนวนคนอ่าน : 3,902