| | |
Save Record - keeps updating with 1st records data
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
The query that updates the hours worked is as follows:
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
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)
Private Sub 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(PayrollDatabaseDataSet.Employee_Hours_Worked_Table) Dim confirm As Integer ' variable to store records Dim row As payrollDatabaseDataSet.Employee_Hours_Worked_TableRow 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.UpdateQueryHoursWorked(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!") End If ' show first record current_row = 0 ShowCurrentRecord()
The query that updates the hours worked is as follows:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Thanks for taking the time to read my post
Laura
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
I am experiencing the same problem w/ vb6 sql server 2005 as data engine
Help PLEASE
Help PLEASE
•
•
•
•
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)
Private Sub 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(PayrollDatabaseDataSet.Employee_Hours_Worked_Table) Dim confirm As Integer ' variable to store records Dim row As payrollDatabaseDataSet.Employee_Hours_Worked_TableRow 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.UpdateQueryHoursWorked(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!") End If ' show first record current_row = 0 ShowCurrentRecord()
The query that updates the hours worked is as follows:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Thanks for taking the time to read my post
Laura
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: help pls in resizing treeview on run
- Next Thread: VB6 Project Groups
Views: 1345 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





