monica73174
asked on
using me.bindingcontext to step through records in a database
I have bound some data to text boxes. I created 2 buttons one to move to the next record and one to move to the previous record. In my book it says I can just use this one line of code to make it happen.
me.bindingcontext(books1, "Books").Position -= 1 or me.bindingcontext(books1, "Books").Position += 1
Why does this code not update the text boxes?
me.bindingcontext(books1, "Books").Position -= 1 or me.bindingcontext(books1, "Books").Position += 1
Why does this code not update the text boxes?
ASKER
Well I created the binding through the wizard and dragged a textbox onto the form with the binding already attached. So basically I let VS do the work.
ASKER
If I use the the databindings property and select a field to bind to the text box is that the same as above?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
yes it is 2005! Sorry I should have said that to begin with. I have a class that it using 2003 and Im using 2005 so far everything has been very similar until we got to the database chapter. Your second answer makes much more sense now. You have been very helpful with my problem. Thank you so much!
me.bindingcontext(DataSour
That is, you have first nominated (what I presume is) a dataset as the datasource and then, separately, nominated (what I presume is) a datatable within that dataset as the datamember. How did you bind to the textboxes? If (as will often happen) you did something like
myTextBox.DataBindings.Add
that is regarded by the binding context as different. The technical structure of that is
myTextBox.DataBindings.Add
In the call to the bindingcontext the datasource is just the dataset whereas in the binding it is the specific datatable within the dataset.
Although they resolve to the same thing, the difference in syntax confuses VB.NET.
That's all a bit theoretical, but hopefully it will give you sufficent guidance as to where the problem might lie. If it doesn't, can you please post the code by which you bind your textboxes to your data?
Roger