ADO.NET 2.0 Question - LearnVisualStudio.Net tutorial

M

Mike W

I ran though the ADO.NET tutorials on www.LearnVisualStudio.Net (also
available from msdn.microsoft.com) for VB 2005 - specifically lesson 9 of
"Visual Basic 2005 Express Edition for Beginners"
To my dismay, after following the tutorial a couple of times, it ends with
the presenters app functioning correctly while mine does not. The issue is
that when we execute the following code to save changes to the database,
then close the app and restart, my changes are not saved while his
apparently are.
------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

'need to get any changes that were made to the bindings source and place in
dataset

Me.BindingSource1.EndEdit() 'propagates changes made to data on form to
dataset

Dim rowsaffected As Integer = 0

rowsaffected = CustomerTableAdapter1.Update(MyCompanyDataSet1.Customer)
'updates database and returns number of rows updated

MessageBox.Show(rowsaffected.ToString)

End Sub

-------------------------------------------

The author of the tutorial was working with Beta 2 so I'm not sure if there
is something missing in the tutorial or perhaps someting I missed twice
while following along.
Any tips on what may be missing are greatly appreciated.

-m
 
C

Cor Ligthert [MVP]

Mike,
Me.BindingSource1.EndEdit() 'propagates changes made to data on form to
dataset

Probably this has to be EndCurrentEdit because that propogates changes made
to data on a form to a dataset.

I hope this helps,

Cor
 
M

Mike W

Unfortunately, the EndCurrentEdit method does not exist in this context.
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/cpref17/html/T_System_Windows_Forms_BindingSource_Members.htm


-m
 
C

Cor Ligthert [MVP]

Mike,
Unfortunately, the EndCurrentEdit method does not exist in this context.

That was why I wrote probably.

Normally we do it in this way.

BindingContext(ds.Tables(0)).EndCurrentEdit()

Where ds.Table(0) represent your table or defaultview of that.

(There are in my opinion still many flaws in the documentation, there is
told that it is one of the major goals to get rid of those, so I am not sure
if this is one, however the EndEdit has never done what you told it should
do.).

http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagrid.endedit.aspx

while this does it.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingmanagerbase.endcurrentedit.aspx

Probably will this do it as well

BindingContext(directcast(BindingSource1,DataTable)).EndCurrentEdit
and if this gives an error than
BindingContext(directcast(BindingSource1,DataView)).EndCurrentEdit

You tell than what object in the bindingsource is affected and do using the
bindingcontext an endcurrentedit on it.

All typed nothing tested so watch errors.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top