天天看點

[VB.NET]ADO資料庫處理-讀出資料記錄

  1. <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
  2. Imports System.Data.OleDb '引入ADO.NET操作命名空間
  3. Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "/Book.mdb")
  4.     Dim MyCommand As OleDbCommand
  5.     Dim MyReader As OleDbDataReader
  6. Dim SQL As String ="SELECT略……"
  7.        Try
  8.             MyConnection.Open()
  9.             MyCommand = New OleDbCommand(SQL, MyConnection)
  10.             MyReader = MyCommand.ExecuteReader()   
  11.             While MyReader.Read '讀取到視窗Text
  12.                 TxtAuthor.Text = MyReader("BookAuthor") 
  13.             End While
  14.         Catch c As Exception
  15.             MsgBox(c.ToString, MsgBoxStyle.Exclamation & MsgBoxStyle.OkOnly, "錯誤")
  16.         End Try
  17.         MyConnection.Close()
  18.         MyReader.Close()
  19.         MyCommand.Dispose()