1

コードには 2 つのセクションがあります。1 つ目は、tbl_Customers というアクセス データベース テーブルのデータを更新します。それはうまくいきます:

Private Sub UpdateRecord()

    Dim imgLocation As String
    imgLocation = idPictureBox.ImageLocation

    Dim cb As New OleDb.OleDbCommandBuilder(da)

    ds.Tables("tbl_Customers").Rows(inc).Item(1) = txtFirstName.Text
    ds.Tables("tbl_Customers").Rows(inc).Item(2) = txtSurname.Text
    ds.Tables("tbl_Customers").Rows(inc).Item(3) = imgLocation
    ds.Tables("tbl_Customers").Rows(inc).Item(4) = mtxtPhoneNumber.Text
    ds.Tables("tbl_Customers").Rows(inc).Item(5) = cbReferred.Text
    ds.Tables("tbl_Customers").Rows(inc).Item(6) = custType

    da.Update(ds, "tbl_Customers")

    MessageBox.Show("Data updated", "Update")

    btnCommit.Enabled = False
    btnClear.Enabled = False
    btnAddNew.Enabled = True
    btnupdate.Enabled = True
    btnDelete.Enabled = True
    btnFirst.Enabled = True
    btnLast.Enabled = True
    btnNext.Enabled = True
    btnPrevious.Enabled = True
    btnFind.Enabled = True

End Sub

2 番目のコードは、tbl_SalesInventory というアクセス データベース テーブルを更新します。このコードは、テーブル内のすべてのレコードを複製します!

Private Sub UpdateItemRecord()

    Dim cb As New OleDb.OleDbCommandBuilder(da10)

    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(1) = txtItemDescription.Text
    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(2) = txtItemMin.Text
    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(3) = txtItemAsk.Text

    Dim SelectedType As Integer = cbSellItemType.SelectedIndex
    Dim Type As Integer = SelectedType + 1
    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(4) = Type.ToString("D2")

    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(5) = txtItemCost.Text
    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(6) = dtpItemPDate.Value

    If lblItemStatusDisplay.Text = "For Sale" Then
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(7) = "F"
    ElseIf lblItemStatus.Text = "On Layaway" Then
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(7) = "L"
    ElseIf lblItemStatus.Text = "Sold" Then
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(7) = "S"
    ElseIf lblItemStatus.Text = "Displayed" Then
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(7) = "D"
    ElseIf lblItemStatus.Text = "Scrapped" Then
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(7) = "X"
    End If

    Try
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(8) = txtDiaMin.Text
    Catch ex As Exception
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(8) = ""
    End Try

    Try
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(9) = txtDiaValue.Text
    Catch ex As Exception
        ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(9) = ""
    End Try

    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(10) = txtItemWeight.Text
    ds10.Tables("tbl_SalesInventory").Rows(incInv).Item(11) = lblItemMeasure.Text

    da10.Update(ds10, "tbl_SalesInventory")

    MessageBox.Show("Data updated", "Update")

    RefreshDataset()
    SortDS10()

    btnCommitItem.Enabled = False
    btnClearItem.Enabled = False
    btnAddItem.Enabled = True
    btnUpdateItem.Enabled = True
    btnDeleteItem.Enabled = True
    btnFirstItem.Enabled = True
    btnLastItem.Enabled = True
    btnNextItem.Enabled = True
    btnPreviousItem.Enabled = True
    btnSearchItem.Enabled = True

End Sub

なぜこれが起こっているのか、誰かが光を当てることができますか? この問題への迅速な対応に感謝します。

4

0 に答える 0