Search code examples
.netvb.netdatagriddatamembertablename

DataGridView.DataMember throws error when assigned a two-part name. i.e. Sales.StoreContact


My problem is outlined here: https://support.microsoft.com/kb/314043 Microsoft says: "This behavior is by design." and no workaround is provided.

I need a workaround.

I have a dataset which is populated correctly with the contents of the table name Sales.StoreContact.

When I try DataGridView1.DataMember="Sales.SalesContact" the IDE throws:

Argument Exception was unhandled.
Child list for field Sales cannot be created.

I don't want to rename my tables either.

the dataset contains

<NewDataSet>
  <Sales.SalesContact>
    <SalesContactID>1</SalesContactID>  
    <Name>Jimmy&lt;/Name>  
    <ReasonType>Damaged&lt;/ReasonType>  
   <ModifiedDate>2010-01-05T00:00:00+00:00&lt;/ModifiedDate>  
  </Sales.SalesContact>  
</NewDataSet>

Solution

  • Update: If your DataTable itself is called "Sales.SalesContact", you could try setting the DataGridView.DataSource property directly to the DataTable (instead of the DataSet):

    Dim salesContactTable As DataTable = dataSet.Tables("Sales.SalesContact")
    dataGridView.DataSource = salesContactTable
    

    So you're saying you have a DataSet called "Sales", which contains a table called "SalesContact"?

    Did you try setting your DataGridView.DataSource property to your "Sales" DataSet and DataGridView.DataMember to simply "SalesContact"?