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

BindingManager Problem

P: n/a
Consider the following:

I have two Access tables: TableA & TableB

TableA is a list of Names with a ZipID

TableB is a list of City, States, and Zips with a ZipID as a primary key
autonumbered

On a Windows Form I have two text boxes, Name (from TableA) and City (from
TableB)

I have the following code:

OleDbDataAdapter nameAdapter = new OleDbDataAdapter("SELECT
FirstName, ZipID from TableA", connection);
OleDbDataAdapter zipAdapter = new OleDbDataAdapter("SELECT ZipID,
City from TableB", connection);

DataSet completeDataSet = new DataSet();

nameAdapter.Fill(completeDataSet, "TableA");
zipAdapter.Fill(completeDataSet, "TableB");
DataRelation relation = completeDataSet.Relations.Add("FullInfo",
completeDataSet.Tables["TableA"].Columns["ZipID"],
completeDataSet.Tables["TableB"].Columns["ZipID"],false);

bManager = this.BindingContext[completeDataSet, "TableA"];
tbxParentField1.DataBindings.Add("Text", completeDataSet,
"TableA.FirstName");
tbxChildField1.DataBindings.Add("Text", completeDataSet,"TableB.City");

I have Next and Previous buttons on the form, with:

bManager.Position += 1; & bManager.Position -= 1; respectively

The form works fine for displaying the FirstName (tbxParentField1) and
scrolling through the records, but the City does not move (tbxChildField1). I
just can't figure out what I am missing when binding the TableB.City field so
that it updates based on the selected FirstName.

Any help would be greatly appreciated.

thanks,
mitch
Nov 1 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Mitch,

Try to bind tbxChildField1 through FullInfo (the relationship, not TableB):

tbxChildField1.DataBindings.Add("Text", completeDataSet,
"TableA.FullInfo.City");
BTW, you might want to consider using a strong-typed DataSet.

--
Dave Sexton

"Mitch W" <Mi****@discussions.microsoft.comwrote in message
news:C6**********************************@microsof t.com...
Consider the following:

I have two Access tables: TableA & TableB

TableA is a list of Names with a ZipID

TableB is a list of City, States, and Zips with a ZipID as a primary key
autonumbered

On a Windows Form I have two text boxes, Name (from TableA) and City (from
TableB)

I have the following code:

OleDbDataAdapter nameAdapter = new OleDbDataAdapter("SELECT
FirstName, ZipID from TableA", connection);
OleDbDataAdapter zipAdapter = new OleDbDataAdapter("SELECT ZipID,
City from TableB", connection);

DataSet completeDataSet = new DataSet();

nameAdapter.Fill(completeDataSet, "TableA");
zipAdapter.Fill(completeDataSet, "TableB");
DataRelation relation = completeDataSet.Relations.Add("FullInfo",
completeDataSet.Tables["TableA"].Columns["ZipID"],
completeDataSet.Tables["TableB"].Columns["ZipID"],false);

bManager = this.BindingContext[completeDataSet, "TableA"];
tbxParentField1.DataBindings.Add("Text", completeDataSet,
"TableA.FirstName");
tbxChildField1.DataBindings.Add("Text",
completeDataSet,"TableB.City");

I have Next and Previous buttons on the form, with:

bManager.Position += 1; & bManager.Position -= 1; respectively

The form works fine for displaying the FirstName (tbxParentField1) and
scrolling through the records, but the City does not move (tbxChildField1).
I
just can't figure out what I am missing when binding the TableB.City field
so
that it updates based on the selected FirstName.

Any help would be greatly appreciated.

thanks,
mitch

Nov 1 '06 #2

P: n/a
Hi Dave,

Thanks for your quick response, it worked like a charm. You gave a BTW, why
do you recommend a strong-typed DataSet.

---mitch

"Dave Sexton" wrote:
Hi Mitch,

Try to bind tbxChildField1 through FullInfo (the relationship, not TableB):

tbxChildField1.DataBindings.Add("Text", completeDataSet,
"TableA.FullInfo.City");
BTW, you might want to consider using a strong-typed DataSet.

--
Dave Sexton

"Mitch W" <Mi****@discussions.microsoft.comwrote in message
news:C6**********************************@microsof t.com...
Consider the following:

I have two Access tables: TableA & TableB

TableA is a list of Names with a ZipID

TableB is a list of City, States, and Zips with a ZipID as a primary key
autonumbered

On a Windows Form I have two text boxes, Name (from TableA) and City (from
TableB)

I have the following code:

OleDbDataAdapter nameAdapter = new OleDbDataAdapter("SELECT
FirstName, ZipID from TableA", connection);
OleDbDataAdapter zipAdapter = new OleDbDataAdapter("SELECT ZipID,
City from TableB", connection);

DataSet completeDataSet = new DataSet();

nameAdapter.Fill(completeDataSet, "TableA");
zipAdapter.Fill(completeDataSet, "TableB");
DataRelation relation = completeDataSet.Relations.Add("FullInfo",
completeDataSet.Tables["TableA"].Columns["ZipID"],
completeDataSet.Tables["TableB"].Columns["ZipID"],false);

bManager = this.BindingContext[completeDataSet, "TableA"];
tbxParentField1.DataBindings.Add("Text", completeDataSet,
"TableA.FirstName");
tbxChildField1.DataBindings.Add("Text",
completeDataSet,"TableB.City");

I have Next and Previous buttons on the form, with:

bManager.Position += 1; & bManager.Position -= 1; respectively

The form works fine for displaying the FirstName (tbxParentField1) and
scrolling through the records, but the City does not move (tbxChildField1).
I
just can't figure out what I am missing when binding the TableB.City field
so
that it updates based on the selected FirstName.

Any help would be greatly appreciated.

thanks,
mitch


Nov 1 '06 #3

P: n/a
Hi Mitch,

If you like to use designer support you can drag your DataSet into the Form
from the Toolbox and bind to it using the property grid.

VS 2005 has increased support for binding.

Also, strong-typed DataSets reduce the amount of code required to work with
data, reduce the amount of casting that is required (introducing type-safety)
and makes code more legible. They also encapsulate the relationships between
the tables, constraints and binding support every time you need the data on
multiple forms instead of having to rewrite the same code over and over again.

--
Dave Sexton

"Mitch W" <Mi****@discussions.microsoft.comwrote in message
news:3E**********************************@microsof t.com...
Hi Dave,

Thanks for your quick response, it worked like a charm. You gave a BTW, why
do you recommend a strong-typed DataSet.

---mitch

"Dave Sexton" wrote:
>Hi Mitch,

Try to bind tbxChildField1 through FullInfo (the relationship, not TableB):

tbxChildField1.DataBindings.Add("Text", completeDataSet,
"TableA.FullInfo.City");
BTW, you might want to consider using a strong-typed DataSet.

--
Dave Sexton

"Mitch W" <Mi****@discussions.microsoft.comwrote in message
news:C6**********************************@microso ft.com...
Consider the following:

I have two Access tables: TableA & TableB

TableA is a list of Names with a ZipID

TableB is a list of City, States, and Zips with a ZipID as a primary key
autonumbered

On a Windows Form I have two text boxes, Name (from TableA) and City
(from
TableB)

I have the following code:

OleDbDataAdapter nameAdapter = new OleDbDataAdapter("SELECT
FirstName, ZipID from TableA", connection);
OleDbDataAdapter zipAdapter = new OleDbDataAdapter("SELECT ZipID,
City from TableB", connection);

DataSet completeDataSet = new DataSet();

nameAdapter.Fill(completeDataSet, "TableA");
zipAdapter.Fill(completeDataSet, "TableB");
DataRelation relation = completeDataSet.Relations.Add("FullInfo",
completeDataSet.Tables["TableA"].Columns["ZipID"],
completeDataSet.Tables["TableB"].Columns["ZipID"],false);

bManager = this.BindingContext[completeDataSet, "TableA"];
tbxParentField1.DataBindings.Add("Text", completeDataSet,
"TableA.FirstName");
tbxChildField1.DataBindings.Add("Text",
completeDataSet,"TableB.City");

I have Next and Previous buttons on the form, with:

bManager.Position += 1; & bManager.Position -= 1; respectively

The form works fine for displaying the FirstName (tbxParentField1) and
scrolling through the records, but the City does not move
(tbxChildField1).
I
just can't figure out what I am missing when binding the TableB.City
field
so
that it updates based on the selected FirstName.

Any help would be greatly appreciated.

thanks,
mitch



Nov 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.