954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problems with saving 1st record

Hey guys

I'm pretty close to finishing this payroll program, but i've run in to yet some more problems and i can't figure out how to fix them.

So, i have various forms representing different tables of my database (Access - the database is connected to my vb application as a data source)

Take for instance the employee table. You can add and delete records from the table as well as make changes to the fields. The add and delete buttons on my form work properly, and if i go to the 2nd record upwards, the save button works, but when i try update the first record, the changes don't stick.

Here is a code snippet. This one is from the Save button for a table called Allowances pay.

' save current record
' variables to store records
Dim row, datar2 As payrollDatabaseDataSet.Allowances_Pay_TableRow
row = PayrollDatabaseDataSet.Allowances_Pay_Table.Rows(current_row)
datar2 = PayrollDatabaseDataSet.Allowances_Pay_Table.Rows(0)
' user must confirm the edit
Dim confirm AsInteger
confirm = MsgBox("Are you sure you want to alter this record", 1 + 48, "Please Confirm")
If confirm = 1 Then
' get new values for variables
row.employee_ID = CStr(Employee_IDTextBox.Text)
row.allowances_ID = Allowances_IDTextBox.Text
row.allowances_amount = Allowances_amountTextBox.Text
Else : MsgBox("Action cancelled!")
EndIf
' update record
Allowances_Pay_TableTableAdapter.Update(row)
Allowances_Pay_TableTableAdapter.Update(PayrollDatabaseDataSet.Allowances_Pay_Table)


I put in a breakpoint just before the update section of the code and checked the values for row.employee_id, etc. The values stored in them are all correct, so i presume it must be the way i'm calling the update procedure.

I'd appreciate any help with this
Thanks
Laura

Loony064
Light Poster
37 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

¤ Could you try this:
Dim row As payrollDatabaseDataSet.Allowances_Pay_TableRow
Dim datar2 As payrollDatabaseDataSet.Allowances_Pay_TableRow

JLCantara
Newbie Poster
6 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 
¤ Could you try this: Dim row As payrollDatabaseDataSet.Allowances_Pay_TableRow Dim datar2 As payrollDatabaseDataSet.Allowances_Pay_TableRow



Unfortunately it made no difference. Any other suggestions?

Loony064
Light Poster
37 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

what is the error message.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

There is no error message. the code runs, but the record just reverts to what it was before the changes were made. i.e. if i change employee name from Benny to Ben and click save, when i go back to that record (after the record is saved, the program displays the first record in the table) record, it is still Benny.

I noticed that this doesn't happen on all my forms (but most) so i'm going to analyze the code and see what the differences are between the code that works 100% properly and the code that doesn't save the first record

Loony064
Light Poster
37 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Since row is actually representing a record, shouldn't it be
set row = PayrollDatabaseDataSet.Allowances_Pay_Table.Rows(current_row)
?
Since you have just declared row as a variant, there might be a typecasting problem here.

aparnesh
Junior Poster
194 posts since Jul 2005
Reputation Points: 20
Solved Threads: 10
 

I'm a bit confused by what you mean. I did do that:

Dim row, datar2 As payrollDatabaseDataSet.Allowances_Pay_TableRow
row = PayrollDatabaseDataSet.Allowances_Pay_Table.Rows(current_row)


Row contains the current record. I also declared Datar2 to store the first record, which i use later in my code for some calculations that i do.

Loony064
Light Poster
37 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Hi,

Hey guys

confirm = MsgBox("Are you sure you want to alter this record", 1 + 48, "Please Confirm")
If confirm = 1 Then
' get new values for variables
row.employee_ID = CStr(Employee_IDTextBox.Text)
row.allowances_ID = Allowances_IDTextBox.Text
row.allowances_amount = Allowances_amountTextBox.Text
Else : MsgBox("Action cancelled!")
EndIf

In above code, after confirm, you are not altering emp name, may that could be the reason..
may be this sort of like should be included.. :

row.employee_Name = CStr(Employee_NameTextBox.Text)

(also Include if any other Cols to update..)

Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

those are the only three fields in that table, so i don't think thats it. why its so weird is that its only the first record that doesn't save. if i go to the next record in the table, and save new amounts, or whatever for it, it saves fine. Just the first one doesn't

Loony064
Light Poster
37 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You