Cannot change DataSource/DataMember atomically

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
I've got a BindingSource Giving me grief now, and I cant find a simple solution.

Suppose i have two datasets called fruit and colour

fruit contains a table called apple

colour contains a table called red


I have a bindingsource1 such that:

VB.NET:
BindingSource1.DataSource = fruit
BindingSource1.DataMember = "apple"



-

now, how do i change this to the other dataset?

if i say:
VB.NET:
BindingSource1.DataSource = colour 'crashes here saying "apple" is not a member of colour
BindingSource1.DataMember = "apple"

if i say:
VB.NET:
BindingSource1.DataMember = "colour" 'crashes says colour is not a member of fruit
BindingSource1.DataSource = fruit


i hoped suspending and resuming the bindings would work, but no
aaaargh, this language is driving me bonkers :eek:
 
Last edited by a moderator:
Umm.. the problem went like this:


I had a brief to make every form in the app searchable. The user can click a button and all the fields go blank, they type anything into any field and the database is searched for all records that match that.

A bit like filter works in microsoft access

My bright idea was to keep the data tables that were loaded with data, and swap out the dataset for another, blank one. That gives the impression of all the fields going blank. The user types and clicks search. The editing of the search dataset is ended and the dataset is passed to a searching form. The form iterates all the tables that were in use/have changes and looks at the values that have changed - the search parameters :)
Using the column datatype from the table, an adhoc query is built up (Parameterised to limit sql injection hacking) and run. the results are shown in a datagrid, and delegates are used to have the parent form show the details of whatever is double clicked on the searching form.
Taking the search form out of there, to have it really behave like filter in MS Access, would have been very nice

But as noted, the hurdle i fell at was simply swapping the dataset that is already bound, out, and swapping in a new blank one for the purposes oif searching

In the end, i gave up, and cleared my bound dataset instead, added one new record to each table i was interested in searching - all the fields went blank as they would when you clear the bound datatables, and off i went.

So, it's working - i'm not happy with the design, but there didnt seem anything i could do
 
Back
Top