0

この削除ボタンを機能させるにはどうすればよいですか?Public Class Form1 Dim inc As Integer Dim MaxRows As Integer Dim dbProvider As String Dim dbSource As String Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String

Private Sub GroupBox1_Enter(sender As System.Object, e As System.EventArgs) Handles GroupBox1.Enter

    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source = C:Desktop\AddressBook\AddressBook.mdb"

    con.ConnectionString = dbProvider & dbSource

    con.Open() 

    sql = "SELECT * From Master_Details"
    da = New OleDb.OleDbDataAdapter(sql, con)
    da.Fill(ds, "Master_Details")

    MaxRows = ds.Tables("Master_Details").Rows.Count
    inc = -1

    MsgBox("Database is now open")
    con.Close()
    MsgBox("Database is now closed")

    txtcode.Text = ds.Tables("Master_Details").Rows(0).Item(0)
    txtdprt.Text = ds.Tables("Master_Details").Rows(0).Item(1)
    txtgroup.Text = ds.Tables("Master_Details").Rows(0).Item(2)
    txtepf.Text = ds.Tables("Master_Details").Rows(0).Item(3)
    txtdesignation.Text = ds.Tables("Master_Details").Rows(0).Item(4)
    txtename.Text = ds.Tables("Master_Details").Rows(0).Item(5)
    txtjdate.Text = ds.Tables("Master_Details").Rows(0).Item(6)
    txtdob.Text = ds.Tables("Master_Details").Rows(0).Item(7)
    txtnicn.Text = ds.Tables("Master_Details").Rows(0).Item(8)
    txtgender.Text = ds.Tables("Master_Details").Rows(0).Item(9)
    txttcodes.Text = ds.Tables("Master_Details").Rows(0).Item(10)
    Return
End Sub

Private Sub btndelete_Click(sender As System.Object, e As System.EventArgs) Handles btndelete.Click
    If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No 
        MsgBox("Operation Cancelled")
        Exit Sub
    End If

    Dim cb As New OleDb.OleDbCommandBuilder(da)

    ds.Tables("Master_Details").Rows(ds.Tables("Master_Details").Rows.Count).Delete()
    MaxRows = MaxRows - 1
    inc = 0
    da.Update(ds, "Master_Details")
    NavigateRecords()
End Sub
4

2 に答える 2

0

usecaseステートメント...これらすべてを削除ボタンクリックイベントに入れます...

  Select Case MsgBox("Do you really want to delete this record?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "CONFIRM DELETE")
        Case MsgBoxResult.Yes
            'NOT SURE IF THIS IS RIGHT, BUT THE SELECT IS IN WHICH YOU WANT...'
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            ds.Tables("Master_Details").Rows(ds.Tables("Master_Details").Rows.Count - 1).Delete()
            MaxRows = MaxRows - 1
            inc = 0
            da.Update(ds, "Master_Details")
            NavigateRecords()
        Case MsgBoxResult.No
             MsgBox ("Operation Cancelled")
           Exit Sub
    End Select

また、メッセージボックスの結果が「はい」の場合は最初の行にブレークポイントを設定し、コードをステップ実行すると、何が起こっているかが表示されます...

ありがとう!

于 2013-02-20T03:53:41.017 に答える
0

削除する行を適切に指定していません。常にds.Tables("Master_Details").Rows.Count最後の行の1つ後の行です。

于 2013-02-20T03:56:38.190 に答える