Updating dataset from bound controls

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
I have lots of textboxes on a form bound at run time to a dataset. How do I reflect any changes made in the textboxes to the dataset then onto the db. I have tried dataset.getchanges then dataadapter.update(dataset,"tablename") but nothing occurs.

Have placed a button with dataset.getchanges then messagebox showing dataset.haschanges
false,
then acceptchanges the messagebox shows false.

AAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaarrrrrrggghhhhh!

Pleeeease help me.

Thanks.

Update:

dim str as String

str = dsStaffData.Tables("Staff").Rows(0)(0, DataRowVersion.Original) & " :" & dsStaffData.Tables("Staff").Rows(0)("Surname", DataRowVersion.Original) & dsStaffData.Tables("Staff").Rows(0)("ForeNames", DataRowVersion.Original)
MsgBox(
"Original Vals: " & str) 'Shows original vals



str = dsStaffData.Tables(
"Staff").Rows(0)(0, DataRowVersion.Current) & " :" & dsStaffData.Tables("Staff").Rows(0)("Surname", DataRowVersion.Current) & dsStaffData.Tables("Staff").Rows(0)("ForeNames", DataRowVersion.Current)
MsgBox(
"Current Vals: " & str)'Still has original vals at this point



str = dsStaffData.Tables(
"Staff").Rows(0)(0, DataRowVersion.Proposed) & " :" & dsStaffData.Tables("Staff").Rows(0)("Surname", DataRowVersion.Proposed) & dsStaffData.Tables("Staff").Rows(0)("ForeNames", DataRowVersion.Proposed)
MsgBox(
"Proposed Vals: " & str)'The edits are here so all as I would expect



dsStaffData.AcceptChanges()
MsgBox(
"Changes Accepted")



str = dsStaffData.Tables(
"Staff").Rows(0)(0, DataRowVersion.Original) & " :" & dsStaffData.Tables("Staff").Rows(0)("Surname", DataRowVersion.Original) & dsStaffData.Tables("Staff").Rows(0)("ForeNames", DataRowVersion.Original)
MsgBox(
"Original Vals: " & str)'Changes reflected in dataset at this point. I'm still ok up to now......



str = dsStaffData.Tables(
"Staff").Rows(0)(0, DataRowVersion.Current) & " :" & dsStaffData.Tables("Staff").Rows(0)("Surname", DataRowVersion.Current) & dsStaffData.Tables("Staff").Rows(0)("ForeNames", DataRowVersion.Current)
MsgBox(
"Current Vals: " & str)'Changes are here so still I am ok.

'THIS Returns false everytime!!!!!!!!! Why has the ds not changed when I've accepted changes??????????
MsgBox(
"Does the dataset have changes man? " & dsStaffData.HasChanges.ToString())
 
Last edited:
Solution to prob

I was missing a call to
Me
.BindingContext(dsStaffData.Tables("Staff")).EndCurrentEdit()

A day and a half I'll never get back :eek:)

pain in the arse!
 
dont accept the changes before you send them to the database

do this:

bindingsource.endedit <-- puts Proposed into Current
adapter.update(table.getchanges()) <--puts Current into DB
table.acceptchanges() <--turns Current into Original



if you accept the changes first, then there wont be anything registering as new or updated... so nothing will be written to the db

see here:
http://msdn2.microsoft.com/en-us/library/system.data.datarowversion.aspx
 
Back
Top