Data Relations and Binding

B

Blake Weaver

Ok folks, I've done plenty of VB6 but I'm new to .Net so I'm coming to you
guys:

I have 3 tables that are related... TableA and TableB have a 1:1
relationship because they are essentially one partitioned table due to
number of columns. I also have TableC which will have one record for only
certain records in TableA/B. (IE a record in TableA may have a one related
record in TableC or none).

Now, I've built a DataAdapter for each table and a DataSet with the
appropriate relations set. I'm binding the fields in TableA to a Datagrid
just so the user has a list to pick through and I'm binding the rest of the
fields from TableA,B & C to textboxes. When I change records in the
datagrid, the textboxes that are bound to TableA reflect the row change
(show the appropriate data for that record). However, the textboxes bound to
TableB/C don't automatically change as they would have in a ADO recordset.
What is the appropriate .Net way of doing this? I'm assuming there is a
better way than manually filtering/finding/Selecting the record in TableB &
C.

Thanks,
Blake
 
W

William Ryan

You'll need to use a DataRelation
http://www.knowdotnet.com/articles/datarelation.html and then use a Binding
Context. Typically, you'll do something like the following
DataGrid.DataSource = DataSet.Table["A"]

Then, on the textboxes... tbFirst.DataBindings.Add("Text", DataSet,
TableName.FieldName)

You'll need to use the DataRelation though so that everything moves to
position

I should have some code later tonight walking through a whole scenario that
I can send you..

HTH,

Bill

P.S. Change the naem you use in your Reply to to something with
(e-mail address removed) or you'll find out the hard way how
much the spammers read these groups.
 
B

Blake Weaver

Bill, Thanks for the pointers.

I've gone over the website you pointed me to and it looks quite useful but I
will have to go back over it again a bit more carefully to get at the
details. But even after the quick glance I took, it leads me to a couple
more questions that are probably a matter of opinion more than anything.

1) In my previous example all 3 of these tables create essentially one large
set of data with 1:1:1 relationships. Therefore, even if you pull them in
prejoined in a single dataadapter, there should be no duplicated parent
rows. So is using that single adapter in this case a viable solution?
....and...
2) You seem to use straight code exclusevily instead of setting the
properties on the Data Controls provided like the SqlConnection and
SqlDataAdapter. Is this a "better" way? Whats the benefit, because obviously
it takes more development time?

Again your help is thoroughly appreciated Bill and don't go writing extra
code on my behalf, the advice and links are plenty.

Blake

William Ryan said:
You'll need to use a DataRelation
http://www.knowdotnet.com/articles/datarelation.html and then use a Binding
Context. Typically, you'll do something like the following
DataGrid.DataSource = DataSet.Table["A"]

Then, on the textboxes... tbFirst.DataBindings.Add("Text", DataSet,
TableName.FieldName)

You'll need to use the DataRelation though so that everything moves to
position

I should have some code later tonight walking through a whole scenario that
I can send you..

HTH,

Bill

P.S. Change the naem you use in your Reply to to something with
(e-mail address removed) or you'll find out the hard way how
much the spammers read these groups.

Blake Weaver said:
Ok folks, I've done plenty of VB6 but I'm new to .Net so I'm coming to you
guys:

I have 3 tables that are related... TableA and TableB have a 1:1
relationship because they are essentially one partitioned table due to
number of columns. I also have TableC which will have one record for only
certain records in TableA/B. (IE a record in TableA may have a one related
record in TableC or none).

Now, I've built a DataAdapter for each table and a DataSet with the
appropriate relations set. I'm binding the fields in TableA to a Datagrid
just so the user has a list to pick through and I'm binding the rest of the
fields from TableA,B & C to textboxes. When I change records in the
datagrid, the textboxes that are bound to TableA reflect the row change
(show the appropriate data for that record). However, the textboxes
bound
to
TableB/C don't automatically change as they would have in a ADO recordset.
What is the appropriate .Net way of doing this? I'm assuming there is a
better way than manually filtering/finding/Selecting the record in
TableB
&
C.

Thanks,
Blake
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top