Visual Studios BindingSource problem

gwarcher
gwarcher used Ask the Experts™
on
I'm having a problem with a very simple application that is merely supposed to scroll through a single table in a dataset.  For some reason, when I debug the application, no data is being populated to the controls.  

This is an assignment, but the book does not address this issue, as I am only supposed to set up the tableadapter and bindingsource and it is supposed to work.  Unless I missed something...

Here is the code.

I've also included the move methods for the button controls.
Private Sub TblScoresBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblScoresBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TblScoresBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.SportsDataSet)

    End Sub

    Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'SportsDataSet.tblScores' table. You can move, or remove it, as needed.
        Me.TblScoresTableAdapter.Fill(Me.SportsDataSet.tblScores)
        Me.TblScoresBindingSource.MoveFirst()


    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.TblScoresBindingSource.MoveNext()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.TblScoresBindingSource.MovePrevious()

    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Try using  TblScoresTableAdapter instead of TableAdapterManager to do the update.

Commented:
OR if you need to use the TableAdapterManager you need to set its TableAdapter property for your table something like:
Dim adapterManager as new TableAdapterManager
adapterManager.TableName1TableAdapter = new TblScoresTableAdapter
adapterManager.UpdateAll(Me.SportsDataSet)

Author

Commented:
The first one gave the error 'UpdateAll' is not a member of 'Sports_Action.SportsDataSetTableAdapters.tblScoresTableAdapter'.

Second one gives an 'undefined' error on both instance initializations.  I placed the code in the NavigatorSaveItem Sub that is above.

Thanks for the help!
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Commented:
So the first one :
Me.TblScoresTableAdapter.Update(Me.SportsDataSet.tblScores)
gives you an error? You can't use UpdateAll when you are using one specific adapter.
You need to use Update only

Author

Commented:
Alright, so the error went away now, but the form itself is still not populating any data.

Here is the updated snippet
Public Class mainForm

    Private Sub TblScoresBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblScoresBindingNavigatorSaveItem.Click
       


        Me.Validate()
        Me.TblScoresBindingSource.EndEdit()
        Me.TblScoresTableAdapter.Update(Me.SportsDataSet)

    End Sub

    Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'SportsDataSet.tblScores' table. You can move, or remove it, as needed.
        Me.TblScoresTableAdapter.Fill(Me.SportsDataSet.tblScores)
        Me.TblScoresBindingSource.MoveFirst()


    End Sub


    Private Sub previousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles previousButton.Click
        Me.TblScoresBindingSource.MovePrevious()

    End Sub

    Private Sub nextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nextButton.Click
        Me.TblScoresBindingSource.MoveNext()
    End Sub
End Class

Open in new window

Commented:
Yeah, the previous code should have worked.
Here is a couple of things:
Are you sure the update statement is executing?
Are you stepping through your code and it does hit that statement with no errors?
When you say the form is not updating, is the database being updated but only the form isnt?
What type of form do you have? How is it bound to the data?

Author

Commented:
I just did a simple drag and drop from the data sources window onto the form.  All of controls are textboxes.  When I stepped through the code it loaded fine, no errors.  Stepping through the moveNext and movePrevious events cause no errors either.

I normally don't use databinding when I work in access...but alas, it's for a class...

Author

Commented:
No I'm not sure if the update statement is executing.  Is there a log that I can see?  When I tried to put a  stop there, the debug didn't pass through that sub, just went right to the form_load event.

Commented:
So you are saying that when you click on the Save button of the navigation toolbar it doesn't execute that code?
Do you have your configuration set to debug instead of release so it stops at breakpoints?

Author

Commented:
Sorry about that...newb mistake.  I put a break at the navigation toolbar and pushed save.  Stepping through caused no errors.  

Your second question, I believe it is set to debug.

Commented:
So it did step through and executed that statement?
Then the question is: is the data saved in the database but not the form or is the data not saved at all?

Author

Commented:
Yes it did.

I checked the database after update and there have been no changes made.

Commented:
Try this instead:
Me.TblScoresTableAdapter.Update(Me.SportsDataSet.tblScores)

Author

Commented:
No such luck.  I even tried a moveNext method just to see if it would clear out the form.

Code stands as follows:


Public Class mainForm

    Private Sub TblScoresBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblScoresBindingNavigatorSaveItem.Click
       


        Me.Validate()
        Me.TblScoresBindingSource.EndEdit()
        Me.TblScoresTableAdapter.Update(Me.SportsDataSet.tblScores)
        Me.TblScoresBindingSource.MoveNext()



    End Sub

    Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'SportsDataSet.tblScores' table. You can move, or remove it, as needed.
        Me.TblScoresTableAdapter.Fill(Me.SportsDataSet.tblScores)
        Me.TblScoresBindingSource.MoveFirst()


    End Sub


    Private Sub previousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles previousButton.Click
        Me.TblScoresBindingSource.MovePrevious()

    End Sub

    Private Sub nextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nextButton.Click
        Me.TblScoresBindingSource.MoveNext()
    End Sub
End Class

Open in new window

Author

Commented:
I'm going to try this on another computer with VS Express and see if there is any difference.

Author

Commented:
bah!  works fine on another computer.  I have a full copy of VS on my laptop running Win7, what do you think could be the problem?

Commented:
Why are you moving first, next and previous?
How is your form bound to the data?
Didn't you just drop the table on your form as a datagridview?
If so you don't need those.
Wasn't the navigation toolbar automatically created?

Commented:
Where does the database reside?

Author

Commented:
inside the source folder of the project

Commented:
Where does the project reside?
Windows 7 doesn't like it when you put things under certain directories.
Can you build the app and run it by right clicking on it and using Run as administrator and that works fine?

Author

Commented:
Interesting unhandled exception when I tried that  Image attached.
exception.PNG

Commented:
Are you using the 64 bit version of Windows 7? And you are probably using Access?
You need to install the Office 2007 data providers then:
http://www.microsoft.com/downloads/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial