天天看点

[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()