1

我有两段代码。第一个更新名为 tbl_Customers 的 access 数据库表中的数据。它工作正常:

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

第二段代码更新名为 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