View Full Version : Save Record - keeps updating with 1st records data


Loony064
06-25-2008, 04:53 PM
Hey guys!

I figured it might be easier to have my various questions in seperate posts, to avoid confusion.

My next problem is that with two of my tables (Hours Worked and Occupations) when i want to save the records, it places the correct values (taken from text boxes on the form) and sets the recordset to thos values, but then for some strange reason, it uses the the data from the first record in the table to update the record.

i.e. Record 1 = employee id: 001 name: "Donald"
Record 2 = employee id: 002 name: "Sammy"
new name for record 2 = "Sam"
thus Record 2 should = employee id: 002 name:Sam
but something in my code causes it to become
employee id:002 name:Donald

here is the code for the hours worked save button

PrivateSub CmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSave.Click
' button to save record
' fill table adapter with records
Employee_Hours_Worked_TableTableAdapter.Fill(Payro llDatabaseDataSet.Employee_Hours_Worked_Table)
Dim confirm AsInteger
' variable to store records
Dim row As payrollDatabaseDataSet.Employee_Hours_Worked_Table Row
row = PayrollDatabaseDataSet.Employee_Hours_Worked_Table .Rows(current_row)
' user must confirm update
confirm = MsgBox("Are you sure you want to alter this record", 1 + 48, "Please Confirm")
If confirm = 1 Then
' fill variables
row.Hours_Worked_Normal = Hours_Worked_NormalTextBox.Text
row.Hours_Worked_Overtime_1 = Hours_Worked_Overtime_1TextBox.Text
row.Hours_Worked_Overtime_1andhalf = Hours_Worked_Overtime_1andhalfTextBox.Text
row.Hours_worked_overtime_2 = Hours_worked_overtime_2TextBox.Text
' update record
Employee_Hours_Worked_TableTableAdapter.UpdateQuer yHoursWorked(row.Hours_Worked_Normal, row.Hours_Worked_Overtime_1, row.Hours_Worked_Overtime_1andhalf, row.Hours_worked_overtime_2, row.Employee_ID)
Else : MsgBox("Action Cancelled!")
EndIf
' show first record
current_row = 0
ShowCurrentRecord()


The query that updates the hours worked is as follows:
UPDATE Employee_Hours_Worked_Table
SET Hours_Worked_Normal = ?, Hours_Worked_Overtime_1 = ?, Hours_Worked_Overtime_1andhalf = ?, Hours_worked_overtime_2 = ?
WHERE (Employee_ID = ?)

And then i'm also getting an error: Column 'Employee_ID' is constrained to be unique. Value '12' is already present, but i'm not (or at least i'm not intending to change the employee_id. i just want to change the number of hours worked where the employee_id is the same as the employee_id in my current row)

These errors have stumped me. Maybe its the lack of sleep or possibly my lack of knowledge, but i'd really, really appreciate some help since i have to get this program finished by next week :eek:

Thanks for taking the time to read my post
Laura