Public Class Form1
Inherits System.Windows.Forms.Form
'Dim myconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\work\gdC\test.mdb;"
'Dim ADC As OleDb.OleDbConnection = New OleDb.OleDbConnection(myconn)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DslisT11.Clear()
OleDbDataAdapter1.Fill(DslisT11, "通信录") 'ERROR -->Fill: SelectCommand.Connection 属性尚未初始化
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.BindingContext(DslisT11, "通信录").Position -= 1
showp()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.BindingContext(DslisT11, "通信录").Position += 1
showp()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox2.Text = Me.Name
End Sub
Private Sub showp()
Dim iCnt As Integer
Dim iPos As Integer
iCnt = Me.BindingContext(DslisT11, "通信录").Count
If iCnt = 0 Then
TextBox2.Text = "(No records)"
Else
iPos = Me.BindingContext(DslisT11, "通信录").Position + 1
TextBox2.Text = iPos.ToString & " of " & iCnt.ToString
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
OleDbDataAdapter1.SelectCommand = New OleDb.OleDbCommand("select top 5 * from 通信录", OleDbConnection1)
DslisT11.Clear()
OleDbDataAdapter1.Fill(DslisT11, "通信录")
End Sub
End Class
HOW TO
refer to
http://doc.readmen.com/1/141059.shtml as the follow
Dim mySelectText As String = "SELECT CustomerID, CompanyName FROM CUSTOMERS"
Dim myConnString As String = "Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"
Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(mySelectText, myConnString)
Solution: add the command string for OleDbDataAdapter1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox2.Text = Me.Name
OleDbDataAdapter1 = New OleDb.OleDbDataAdapter("select * from 通信录", OleDbConnection1)
End Sub
[FINISH]
posted on 2006-11-12 15:33
MT'S BLOG 阅读(3210)
评论(0) 编辑 收藏 引用