Display Data from Access 2003 DB

  • Thread starter Thread starter Rafael
  • Start date Start date
R

Rafael

All,

I'm looking for a "newbie" friendly example/tutorial that will show me
step-by-step how to display data from Access DB on a comboBox control on a
WinForm.

Here is what I've done so far:

1. Created Access DB with two tables: Users, Tasks
2. Created Table Called Users which contains 3 columns: ID, NAME, WEBSITE
3. Added a Data Source to the Windows Aplication project
4. I selected my table and added all the controls to my form
5. I am able to view data when I use the "bindingNavigator"

However, what I want to do is have the list of values in the NAME column
available for selection when the form loads. Once a value is selected, do a
query on the Tasks table to return those values matching the selection on
the NAME comboBox. The result of the query will be added as a recordset to
Tasks ComboBox.

Thank you for your help!

Rafael
 
All,

I'm looking for a "newbie" friendly example/tutorial that will show me
step-by-step how to display data from Access DB on a comboBox control on a
WinForm.

Here is what I've done so far:

1. Created Access DB with two tables: Users, Tasks
2. Created Table Called Users which contains 3 columns: ID, NAME, WEBSITE
3. Added a Data Source to the Windows Aplication project
4. I selected my table and added all the controls to my form
5. I am able to view data when I use the "bindingNavigator"

However, what I want to do is have the list of values in the NAME column
available for selection when the form loads. Once a value is selected, do a
query on the Tasks table to return those values matching the selection on
the NAME comboBox. The result of the query will be added as a recordset to
Tasks ComboBox.

Thank you for your help!

Rafael
I believe you are using a BindingSource to populate the controls on the form and
you want a ComboBox or ListBox on the form instead of the TextBox for the name
column. Is that right?

If it is, you may have to do the BindingSource creation again.

Look in the Data Sources window of the IDE and find the field you want to be
created as a list box. If you click on it you will see that it has a drop down
list of the controls you can bind it to. Choose the combo or list box from the
list. Now drag the dataSource to the form and the IDE will create the object
you chose for that column.

You will have to link that list box to the table with the names in it to
populate that list. VS 2005 has good instructions for doing this in the help.

Now for a warning: You should not use this method of binding data to your
controls, because it makes changing the application much more difficult if you
need to.

For instance to change from what you already have done you will probably have to
delete all of the created controls from your form and start again. It's not a
big deal if you have no hand-written code on the form, but consider what you
will have to do if you should need to change the data binding at a later time.

I hope this has been helpful.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
Thanks Otis,

I follow everything you said except for the "critical" part since again, not
sure what to look for: "You will have to link that list box to the table
with the names in it to populate that list. VS 2005 has good instructions
for doing this in the help" How is this done?

I'm trying to replicate what I have working on Access so here is some silly
achitecture of my data source in Access.

Table1: two columns:
ID=1, CATEGORY=Fruit
ID=2, CATEGORY=Vegetable

Table2: Three Columns:
ID=1, FromState=CA, CATEGORY=Fruit
ID=2, FromState=NY, CATEGORY=Vegetable

Table3: Three Columns:
ID=1, COLOR=Green, FromState=CA
ID=2, COLOR=Orange, FromState=NY

If user selects Fruit from Table1, only Fruit items from Table2 should be
display as option on ComboBox2 (FromState). If he user selects CA as the
FromState, then only items from CA should be displayed on ComboBox3.

Thanks again and sorry for the basic nature of this question!

Rafael

I've changed the text box to a combobox and draged the combobox to my form.
The only issue is
 
Thanks Otis,

I follow everything you said except for the "critical" part since again, not
sure what to look for: "You will have to link that list box to the table
with the names in it to populate that list. VS 2005 has good instructions
for doing this in the help" How is this done?

I'm trying to replicate what I have working on Access so here is some silly
achitecture of my data source in Access.

Table1: two columns:
ID=1, CATEGORY=Fruit
ID=2, CATEGORY=Vegetable

Table2: Three Columns:
ID=1, FromState=CA, CATEGORY=Fruit
ID=2, FromState=NY, CATEGORY=Vegetable

Table3: Three Columns:
ID=1, COLOR=Green, FromState=CA
ID=2, COLOR=Orange, FromState=NY

If user selects Fruit from Table1, only Fruit items from Table2 should be
display as option on ComboBox2 (FromState). If he user selects CA as the
FromState, then only items from CA should be displayed on ComboBox3.

Thanks again and sorry for the basic nature of this question!

Rafael
[snip]

Now you will have top populate the combobox(s) by binding it to the table that
has the lookup data. You will do this by defining relationships between the
tables. I'm sorry, but I don't do this often enough to give you specific
instructions, but it goes something like this.

In your project explorer (usually on the right hand side of the IDE) you will
find a *.xsd file named *DataSet.xsd. If you open it you should see your three
tables in it. You will need to define the relationships between them much like
you would in Access.

If you can find a copy of Jesse Liberty's book "Visual C# 2005 ADeveloper's
NoteBook", Chapter 5 has instructions for doing what you are trying to do there.

You see, even using the technique you are using, it is somewhat complicated and
hard for me to explain. I feel as though I'm not being much help. I think you
will need to do some research to accomplish your task, my friend.

Again a warning: Doing it the way you are will lead to difficulty down the road
as I described in my last post.

During this week I will put a sample on my web site of doing what you are doing
without using the drag and drop way.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
As Otis said, it's hard to explain. The 2005 help has an article
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclictl/html/4ce35f12-1f4e-4317-92d1-af8686a8cfaa.htm
You can also search for How to: Create a Lookup Table for a Windows Forms
ComboBox

HTH,
Brian
 
Otis you're being a great help and thanks for your patience! I am not set
on the idea of using this method I arrived to this way of doing due to my
lack of knowledge of the product so any other/better way of doing it that I
can use will be fine by me.

I'll take a look at your website for examples on this stuff.

Thanks,

Rafael
Otis Mukinfus said:
Thanks Otis,

I follow everything you said except for the "critical" part since again,
not
sure what to look for: "You will have to link that list box to the table
with the names in it to populate that list. VS 2005 has good instructions
for doing this in the help" How is this done?

I'm trying to replicate what I have working on Access so here is some
silly
achitecture of my data source in Access.

Table1: two columns:
ID=1, CATEGORY=Fruit
ID=2, CATEGORY=Vegetable

Table2: Three Columns:
ID=1, FromState=CA, CATEGORY=Fruit
ID=2, FromState=NY, CATEGORY=Vegetable

Table3: Three Columns:
ID=1, COLOR=Green, FromState=CA
ID=2, COLOR=Orange, FromState=NY

If user selects Fruit from Table1, only Fruit items from Table2 should be
display as option on ComboBox2 (FromState). If he user selects CA as the
FromState, then only items from CA should be displayed on ComboBox3.

Thanks again and sorry for the basic nature of this question!

Rafael
[snip]

Now you will have top populate the combobox(s) by binding it to the table
that
has the lookup data. You will do this by defining relationships between
the
tables. I'm sorry, but I don't do this often enough to give you specific
instructions, but it goes something like this.

In your project explorer (usually on the right hand side of the IDE) you
will
find a *.xsd file named *DataSet.xsd. If you open it you should see your
three
tables in it. You will need to define the relationships between them much
like
you would in Access.

If you can find a copy of Jesse Liberty's book "Visual C# 2005
ADeveloper's
NoteBook", Chapter 5 has instructions for doing what you are trying to do
there.

You see, even using the technique you are using, it is somewhat
complicated and
hard for me to explain. I feel as though I'm not being much help. I
think you
will need to do some research to accomplish your task, my friend.

Again a warning: Doing it the way you are will lead to difficulty down
the road
as I described in my last post.

During this week I will put a sample on my web site of doing what you are
doing
without using the drag and drop way.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
Ah, I found the trick to binding controls to my datbase tables on this
article:
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_mclictl/html/622fce80-879d-44be-abbf-8350ec22ca2b.htm

My next thing is figuring out how to create filters on these tables as the
data on one control changes.

I hope you have some code for this part.

Thanks,

Rafael
 
Back
Top