Updating a database
Question from a newbie:
I am playing around with the various topics in "Beginning Visual C#" and I am stuck on a problem.
I have worked through the section on updating a database (beginning on page 622) and everything works great but what I would like to do is specify a row to update.
What I have at the moment is this:
private void btnUpdate_Click(object sender, System.EventArgs e)
{
_adapter.UpdateCommand = new OleDbCommand("UPDATE tbl_person SET first_name = '" +
_dataset.Tables["tbl_person"].Rows[0]["first_name"] + "', last_name = '" +
_dataset.Tables["tbl_person"].Rows[0]["last_name"] + "' WHERE pay_no = '" +
_dataset.Tables["tbl_person"].Rows[0]["pay_no"] + "'", _connection);
_adapter.Update(_dataset, "tbl_person");
}
and it works really well if I specify which row to update eg 0, 1, 2 etc by physically changing the value of the row.
What I would like to do is pass the row value to the SQL command according to the field that is currently displayed. eg if fred bloggs details are on the screen (lets say he's record 3) and I click the update button then I want it to pass the record value to the SQL update command.
I would like to ask everyone their thoughts on how to do this because I think I am confusing myself with it somewhere along the line and I'm getting nowhere.
Thanks in advance....:)
|