943,983 Members | Top Members by Rank

Ad:
Jun 25th, 2008
0

Save Record - keeps updating with 1st records data

Expand Post »
Hey guys!

I figured it might be easier to have my various questions in separate 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 those values, but then for some strange reason, it uses 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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub CmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSave.Click
  2. ' button to save record
  3. ' fill table adapter with records
  4. Employee_Hours_Worked_TableTableAdapter.Fill(PayrollDatabaseDataSet.Employee_Hours_Worked_Table)
  5. Dim confirm As Integer
  6. ' variable to store records
  7. Dim row As payrollDatabaseDataSet.Employee_Hours_Worked_TableRow
  8. row = PayrollDatabaseDataSet.Employee_Hours_Worked_Table.Rows(current_row)
  9. ' user must confirm update
  10. confirm = MsgBox("Are you sure you want to alter this record", 1 + 48, "Please Confirm")
  11. If confirm = 1 Then
  12. ' fill variables
  13. row.Hours_Worked_Normal = Hours_Worked_NormalTextBox.Text
  14. row.Hours_Worked_Overtime_1 = Hours_Worked_Overtime_1TextBox.Text
  15. row.Hours_Worked_Overtime_1andhalf = Hours_Worked_Overtime_1andhalfTextBox.Text
  16. row.Hours_worked_overtime_2 = Hours_worked_overtime_2TextBox.Text
  17. ' update record
  18. Employee_Hours_Worked_TableTableAdapter.UpdateQueryHoursWorked(row.Hours_Worked_Normal, row.Hours_Worked_Overtime_1, row.Hours_Worked_Overtime_1andhalf, row.Hours_worked_overtime_2, row.Employee_ID)
  19. Else : MsgBox("Action Cancelled!")
  20. End If
  21. ' show first record
  22. current_row = 0
  23. ShowCurrentRecord()

The query that updates the hours worked is as follows:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. UPDATE Employee_Hours_Worked_Table
  2. SET Hours_Worked_Normal = ?, Hours_Worked_Overtime_1 = ?, Hours_Worked_Overtime_1andhalf = ?, Hours_worked_overtime_2 = ?
  3. 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

Thanks for taking the time to read my post
Laura
Reputation Points: 10
Solved Threads: 0
Light Poster
Loony064 is offline Offline
37 posts
since Sep 2006
Nov 3rd, 2009
0

OMG did you ever get this resolved.

I am experiencing the same problem w/ vb6 sql server 2005 as data engine

Help PLEASE


Click to Expand / Collapse  Quote originally posted by Loony064 ...
Hey guys!

I figured it might be easier to have my various questions in separate 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 those values, but then for some strange reason, it uses 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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub CmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSave.Click
  2. ' button to save record
  3. ' fill table adapter with records
  4. Employee_Hours_Worked_TableTableAdapter.Fill(PayrollDatabaseDataSet.Employee_Hours_Worked_Table)
  5. Dim confirm As Integer
  6. ' variable to store records
  7. Dim row As payrollDatabaseDataSet.Employee_Hours_Worked_TableRow
  8. row = PayrollDatabaseDataSet.Employee_Hours_Worked_Table.Rows(current_row)
  9. ' user must confirm update
  10. confirm = MsgBox("Are you sure you want to alter this record", 1 + 48, "Please Confirm")
  11. If confirm = 1 Then
  12. ' fill variables
  13. row.Hours_Worked_Normal = Hours_Worked_NormalTextBox.Text
  14. row.Hours_Worked_Overtime_1 = Hours_Worked_Overtime_1TextBox.Text
  15. row.Hours_Worked_Overtime_1andhalf = Hours_Worked_Overtime_1andhalfTextBox.Text
  16. row.Hours_worked_overtime_2 = Hours_worked_overtime_2TextBox.Text
  17. ' update record
  18. Employee_Hours_Worked_TableTableAdapter.UpdateQueryHoursWorked(row.Hours_Worked_Normal, row.Hours_Worked_Overtime_1, row.Hours_Worked_Overtime_1andhalf, row.Hours_worked_overtime_2, row.Employee_ID)
  19. Else : MsgBox("Action Cancelled!")
  20. End If
  21. ' show first record
  22. current_row = 0
  23. ShowCurrentRecord()

The query that updates the hours worked is as follows:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. UPDATE Employee_Hours_Worked_Table
  2. SET Hours_Worked_Normal = ?, Hours_Worked_Overtime_1 = ?, Hours_Worked_Overtime_1andhalf = ?, Hours_worked_overtime_2 = ?
  3. 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

Thanks for taking the time to read my post
Laura
Reputation Points: 10
Solved Threads: 0
Newbie Poster
esspeter is offline Offline
2 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: help pls in resizing treeview on run
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB6 Project Groups





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC