Save Record - keeps updating with 1st records data

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 27
Reputation: Loony064 is an unknown quantity at this point 
Solved Threads: 0
Loony064's Avatar
Loony064 Loony064 is offline Offline
Light Poster

Save Record - keeps updating with 1st records data

 
0
  #1
Jun 25th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 2
Reputation: esspeter is an unknown quantity at this point 
Solved Threads: 0
esspeter esspeter is offline Offline
Newbie Poster

OMG did you ever get this resolved.

 
0
  #2
Nov 3rd, 2009
I am experiencing the same problem w/ vb6 sql server 2005 as data engine

Help PLEASE


Originally Posted by Loony064 View 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
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC