![]() |
#2
不说也罢2011-07-11 18:03
1、如果你写了MsgBox(ex.Message),就知道错误出现在哪里了。
2、这是因为你在button3中BindingContext所使用的DATASET与实际绑定的DATASET不一致所导致的。 我给你改了一下: ![]() Dim ds As New DataSet Private Sub command1_click() Handles Button1.Click Try Me.TextBox1.DataBindings.Clear() Me.TextBox2.DataBindings.Clear() Dim strcn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\t_login.mdb" Dim cn As New OleDbConnection(strcn) ' Dim command As OleDbCommand Dim ap As New OleDbDataAdapter cn.Open() Dim mysql As String mysql = "select id,password1 from t_login" ap = New OleDbDataAdapter(mysql, cn) ap.Fill(ds, "t_login") Me.TextBox1.DataBindings.Add("text", ds, "t_login.id") Me.TextBox2.DataBindings.Add("text", ds, "t_login.password1") cn.Close() Catch ex As Exception MsgBox(ex.Message) MsgBox("有錯我就出現") Exit Sub End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.TextBox1.BindingContext(ds, "t_login").Position = 0 End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.TextBox1.BindingContext(ds, "t_login").Position += 1 End Sub |
private sub command1_click()
Dim strcn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\t_login.mdb"
Dim cn As New OleDbConnection(strcn)
' Dim command As OleDbCommand
Dim ap As New OleDbDataAdapter
Dim ds As New DataSet
cn.Open()
Dim mysql As String
mysql = "select id,password1 from t_login"
ap = New OleDbDataAdapter(mysql, cn)
ap.Fill(ds, "t_login")
cn.Close()
Me.TextBox1.DataBindings.Add("text", ds, "t_login.id")
Me.TextBox2.DataBindings.Add("text", ds, "t_login.password1")
Catch ex As Exception
MsgBox("有錯我就出現")
Exit Sub
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.TextBox1.BindingContext(ds, "t_login").Position = 0
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.TextBox1.BindingContext(ds, "t_login").Position += 1
End Sub
End Class
點觸發了,下一 頁後,再點顯示,不會重新檢索數據,還是下一頁那筆數據
[ 本帖最后由 jxyga111 于 2011-7-12 11:59 编辑 ]