Runtime DataSource Selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I use the Data Source Wizard to set up my project for using an Access
Database file, it seems to hard-code the file path of the MDB file into the
project.

This makes it not possible to allow the user to specify what MDB file he
wants to use at run-time.

But yet, it seems I have no alternative but to use the Wizard if I want to
be able to use the data binding features of the Windows Forms controls.

This is a worse situation even than in VB 6 ! At least in VB 6 I could set
the data source property of the Data Control at run-time, but here with .NET,
I am forced to use a fixed data source location!

Can anyone offer a solution?
 
I'm not sure where you got that you have to use any of the wizards to use
databinding in windows forms. The 2 things are completely unrelated.

All the wizards do is generate code. It is the same code you could write
yourself.

So just write your own data access code, and just do the binding yourself.
Your code is likely to be far more readable, far more manageable and
maintainable. It sounds like you just need to read up on how to do all
this. But just because you don't know how to do it, doesn't mean it can't
be done.
 
Hi Marina,

Thanks for your reply. I have looked at the MSDN topics on databinding, and
the only thing they tell is how to use the wizards.

Can you let me know what I should search on to find topics that give an
overview of the do-it-yourself method?
 
I don't know what the correct terms are to find the search. In general,
controls such as textboxes, etc, have a DataBindings collection. You can
add bindings to bind a particular column in your datasource to a property of
the control (such as Text, for example).

For grid like controls, you typically set the DataSource property.

I wouldn't limit your search to MSDN, they like to promote their wizards and
such. Use google/google groups.

Btw, just looking in my visual studio help collection, under the 'binding
data' topic, there is 'windows forms' for windows forms databinding. Off of
that page there are links to help topics such as 'Creating a Simple Bound
Control on a windows form'. This shows you how to do it in the properties
window, but you could just write the same code by hand of course. It took
me just a few seconds to find this topic.
 
Back
Top