当我更新Access数据库时为什么我的记录变得相同?

时间:2015-03-08 15:35:16

标签: vb.net

为什么我的DataGridView显示的值与我在所有记录(行)中输入的值相同?例如,我在Access中有12条记录,但是当我尝试更新记录时,记录会被保存并更改,但它会应用于所有12条记录,而不仅仅是我选择的记录。

  

MemberID FirstName
  0001 Tan Poh Yun
  0002 Tan Poh Yun
  0003 Tan Poh Yun
  0004 Tan Poh Yun
  0005 Tan Poh Yun
  0006 Tan Poh Yun
  0007 Tan Poh Yun
  0008 Tan Poh Yun
  0009 Tan Poh Yun
  0010 Tan Poh Yun
  0011 Tan Poh Yun
  0012 Tan Poh Yun

这里是我的代码:

Private Sub bttnSave_Click(sender As Object, e As EventArgs) Handles bttnSave.Click
    i = MemberDataGridView.CurrentRow.Index

    searchmemberID.Text = MemberDataGridView.Item(0, i).Value
    txtMemberName.Text = MemberDataGridView.Item(1, i).Value
    MemberGender.Text = MemberDataGridView.Item(2, i).Value
    MEMBERIC.Text = MemberDataGridView.Item(3, i).Value
    MemberEmail.Text = MemberDataGridView.Item(4, i).Value
    MemberHandphone.Text = MemberDataGridView.Item(5, i).Value
    MemberAddress.Text = MemberDataGridView.Item(6, i).Value
    txtMemberName.Enabled = True
    MemberEmail.Enabled = True
    MemberHandphone.Enabled = True
    MemberAddress.Enabled = True
    Dim com As OleDbCommand
    com = New OleDbCommand("Update Member set [FirstName] =@sno", acsconn)
    com.Parameters.AddWithValue("@sno", txtMemberName.Text)
    com.ExecuteNonQuery()
    MsgBox("Record Saved")

1 个答案:

答案 0 :(得分:1)

因为您错过了SQL中的where子句。如果没有where子句,它将更新所有记录。你可以这样做:

  UPDATE table_name SET column1=value1 WHERE some_column=some_value;