如何使用vb.net更新访问中特定行和列中的值

时间:2018-06-01 07:23:23

标签: vb.net ms-access

Private Sub btnUpdateu3_Click(sender As Object, e As EventArgs) Handles btnUpdateu3.Click
        cmdInsert.CommandText = "Insert into ecd (first_name, last_name, relationship, phone_number)" + "Values('" + txtefnu3.Text + "','" + txtelnu3.Text + "','" + txterelu3.Text + "', '" + txtecnu3.Text + "')" + "Where student_id('" + txtsidu3.Text + "');"
        cmdInsert.CommandType = CommandType.Text
        cmdInsert.Connection = cnnOLEDB
        cmdInsert.ExecuteNonQuery()
        MessageBox.Show("Insertion Successful")

End Sub

1 个答案:

答案 0 :(得分:0)

您似乎需要更新查询,而不是插入。

Private Sub btnUpdateu3_Click(sender As Object, e As EventArgs) Handles btnUpdateu3.Click
        cmdInsert.CommandText = "UPDATE ecd SET first_name = '" + txtefnu3.Text + "', last_name = '" + txtelnu3.Text + "', relationship = '" + txterelu3.Text + "', phone_number = '" + txtecnu3.Text + "' WHERE student_id = '" + txtsidu3.Text + "';"
        cmdInsert.CommandType = CommandType.Text
        cmdInsert.Connection = cnnOLEDB
        cmdInsert.ExecuteNonQuery()
        MessageBox.Show("Insertion Successful")
End Sub

假设一个非数字学生ID(根据你的原件)。如果学生ID字段是数字,那么您不应该包装单引号(例如')。