By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,088 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,088 IT Pros & Developers. It's quick & easy.

Dataset relations, MSAccess database

P: n/a
Greetings.
I am building a c# windows forms app to show tables from a ms access
database.
I am using OleDbConnection with Microsoft.Jet.OLEDB.4.0 , 5 datagrids
and some data relations to show on
datagrid1 - all jobs
datagrid2 - receipts for the selected job on dg1
datagrid3 - receipt_items for the selected receipt on dg2
datagrid4 - all categories
datagrid5 - receipt items only for the selected job and for the
selected category (the problem)

The tables are:

jobs
id | title

suppliers
id | title

categories
id | category

receipts
id | id_job | id_supplier | title

receipt_items
id | id_receipt | id_category | price

I need some help on the data relation for to filter data to show on
datagrid5.

Here is some sample code i am using to crate a data relation. I get an
exception when calling datagrid5.DataMember = value :

[...]
dbAdapterJobs = new OleDbDataAdapter("SELECT * FROM jobs ORDER BY title
ASC", dbConnection);
dbAdapterJobs.TableMappings.Add("Table", "jobs");
dbAdapterJobs.Fill(ds); // ds is the DataSet
[...]
// Establish the Relationship "RelJobsReceipts"
// between jobs---< receipts
System.Data.DataRelation relJobsReceipts;
System.Data.DataColumn colMaster1;
System.Data.DataColumn colDetail1;
colMaster1 = ds.Tables["jobs"].Columns["id"]; //column must have unique
values
colDetail1 = ds.Tables["receipts"].Columns["id_job"];
relJobsReceipts = new System.Data.DataRelation("RelJobsReceipts",
colMaster1, colDetail1);
ds.Relations.Add(relJobsReceipts);
[...]
// Establish the Relationship "RelCategoriesReceiptItems"
// between categories ---< receipt_items
System.Data.DataRelation relCategoriesReceiptItems;
System.Data.DataColumn colMaster4;
System.Data.DataColumn colDetail4;
colMaster4 = ds.Tables["categories"].Columns["id"];
colDetail4 = ds.Tables["receipt_items"].Columns["id_category"];
relCategoriesReceiptItems = new
System.Data.DataRelation("RelCategoriesReceiptItem s", colMaster4,
colDetail4);
ds.Relations.Add(relCategoriesReceiptItems);
[...]
// Databinding for the Grid's
dg1.DataSource = dsView;
dg1.DataMember = "jobs";
dg2.DataSource = dsView;
dg2.DataMember = "jobs.RelJobsReceipts";
dg3.DataSource = dsView;
dg3.DataMember = "jobs.RelJobsReceipts.RelReceiptsReceiptItems" ;
dg4.DataSource = dsView;
dg4.DataMember = "categories";
dg5.DataSource = dsView;
dg5.DataMember = "categories.RelCategoriesReceiptItems"; // EXCEPTION
IN THS LINE: Child list for field categories cannot be created.
Also, how can I costumize the data on the datagrid? i can't do it in
the designer directly.

Thanks in advance.
Pedro.

Jan 4 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.