2017-06-25 10 views
-1

私は、私のレコードをナビゲートしようとしているが、私は、ボタンを押すと、何も起こりません。私はJet 4.0とAccess DBを使用しています。Vb.netナビゲーション

私は間違っているとは確信していませんが、誰かが正しい方向に私を助けることができるなら、それは高く評価されます。

コード:あなたは常にゼロにcurrentRowの設定ShowDataで

Private Sub showData(ByVal CurrentRow) 

    CurrentRow = 0 

    Dad.Fill(dst, "patrolDB") 

    TextBox27.Text = dst.Tables("patrolDB").Rows(CurrentRow)("ID").ToString.ToUpper 
    DateTimePicker1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroldate").ToString.ToUpper 
    TextBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltime").ToString.ToUpper 
    ComboBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltype").ToString.ToUpper 
    ComboBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolsite").ToString.ToUpper 
    ComboBox4.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolloc").ToString.ToUpper 
    ComboBox3.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolofficer").ToString.ToUpper 
    RichTextBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolnotes").ToString.ToUpper 




Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click 

    If CurrentRow <> dst.Tables("patrolDB").Rows.Count - 1 Then 

     CurrentRow += 1 
     showData(CurrentRow) 

    End If 
    MsgBox("You've reached the last record.") 

End Sub 

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click 
    index = 0 
    showData(CurrentRow) 
End Sub 

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click 
    If CurrentRow <> 0 Then 


     CurrentRow -= 1 
     showData(CurrentRow) 

    End If 

    MsgBox("You've reached the first record.") 

End Sub 

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click 

    CurrentRow = dst.Tables("patrolDB").Rows.Count - 1 
    showData(CurrentRow) 
End Sub 
+3

。これにより、常に最初の行が表示されます。それを取り外します(とないShowDataへの各呼び出しで、一度だけDataSetを記入する方法を見て) – Steve

+0

あなたが最後に読む[尋ねる]と[ツアー]を取る後にあなたもNETがためにその多くを行うようにするデータバインディングの中に見ることができますあなたと多くのコードを取り除く – Plutonix

答えて

0
Dim table As DataTable 

Private Sub LoadData() 
    CurrentRow = 0 
    Dad.Fill(dst, "patrolDB") 
    table = dst.Tables("patrolDB") 'for the comfort 
    ShowCurrentRow() 
End Sub 

Private Sub ShowCurrentRow() 
    TextBox27.Text = table.Rows(CurrentRow)("ID").ToString.ToUpper 
    DateTimePicker1.Text = table.Rows(CurrentRow)("patroldate").ToString.ToUpper 
    TextBox2.Text = table.Rows(CurrentRow)("patroltime").ToString.ToUpper 
    ComboBox1.Text = table.Rows(CurrentRow)("patroltype").ToString.ToUpper 
    ComboBox2.Text = table.Rows(CurrentRow)("patrolsite").ToString.ToUpper 
    ComboBox4.Text = table.Rows(CurrentRow)("patrolloc").ToString.ToUpper 
    ComboBox3.Text = table.Rows(CurrentRow)("patrolofficer").ToString.ToUpper 
    RichTextBox1.Text = table.Rows(CurrentRow)("patrolnotes").ToString.ToUpper 
End Sub 

'go to next 
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click 
    If CurrentRow <> table.Rows.Count - 1 Then 
     CurrentRow += 1 
     ShowCurrentRow() 
    Else MsgBox("You've reached the last record.") 
    End If 
End Sub 

'go to prev 
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click 
    If CurrentRow <> 0 Then 
     CurrentRow -= 1 
     ShowCurrentRow() 
    Else MsgBox("You've reached the first record.") 
    End If 
End Sub 

'go to start 
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click 
    index = 0 
    ShowCurrentRow() 
End Sub 

'go to last 
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click 
    CurrentRow = table.Rows.Count - 1 
    ShowCurrentRow() 
End Sub 
関連する問題