0

I have two tables (Person and Company). Both tables have a field 'Id' (e.g. Person.Id and Company.Id) and the tables are joined on Person.CompanyId = Company.Id

When using DataBindings.Add() to a textbox for example - using WinForms and VB .Net - I would like to use method suggested by Microsoft namely:

txtPersonId.DataBindings.Add("Text", objDataView, "Person.Id")
txtCompanyId.DataBindings.Add("Text", objDataView, "Company.Id")

In this case, I get the following error however: "Child list for field Person cannot be created". After some fiddling around, it looks like 'Person' is looked up as a field in objDataSet instead of 'Person.Id'.

After I change the SQL query and have Person.Id returned as the alias 'PersonId' and Company.Id as 'CompanyId' the following code does work:

txtPersonId.DataBindings.Add("Text", objDataView, "PersonId")
txtCompanyId.DataBindings.Add("Text", objDataView, "CompanyId")

My question is therefor: Why is the Microsoft example not working here (see example here) and how can one include the table name in a DataBindings.Add() method otherwise?

etri
  • 99
  • 8
  • Sorry, typo. Will modify the example... – etri Aug 04 '17 at 16:30
  • See [winforms databinding works only on development machine](https://stackoverflow.com/a/11023821/719186) – LarsTech Aug 04 '17 at 16:35
  • How would I have to use this example you link to? The link in the above link doesn't work for me btw ("The content that you requested cannot be found or you do not have permission to view it. ") – etri Aug 04 '17 at 16:41
  • Put your objDataView in a BindingSource and use the BindingSource in your DataBindings. – LarsTech Aug 04 '17 at 16:43
  • I added 'Dim bs = New BindingSource(objDataView, Nothing)' and 'txtPersonId.DataBindings.Add("Text", bs, "Person.Id")' but this doesn't work either... – etri Aug 04 '17 at 16:47
  • What is `objDataView`? If this is `DataSet` (as in Microsoft example) does dataset have tables `Person` and `Company` in there? – Fabio Sep 09 '17 at 05:36
  • ojDataView is a DataView object and has both tables in them. I guess that it doesn't work because of the non-unique field names ("Id") for both Person and Company...?! Because it does work if I make the field names unique; as shown in my example. – etri Sep 09 '17 at 09:35
  • `DataView` represents a databindable, customized view of a `DataTable`. Where `DataTable` contains data of only one table. Microsoft's example you talking about using `DataSet` which can contain multiple DataTables and supports binding to "child" tables `Customer.Id`. – Fabio Sep 09 '17 at 11:00

0 Answers0