Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I get that error to this line: tblDataSet.Tables.Add(Table_c);

Does anyone know how can I solve it? Thanks in advance.

This is the code:


C#
private DataTable Table_c; // Table_c is imported from a local database
private DataTable Table_a; // Table_a is imported from a local database
private DataSet tblDataSet;

private void Form1_Load(object sender, EventArgs e)
{
    this.table_aTableAdapter1.Fill(this.DBDataSet1.Table_a);

    this.table_cTableAdapter.Fill(this.DBDataSet1.Table_c);

    tblDataSet = new DataSet();
    tblDataSet.Tables.Add(Table_c);
    tblDataSet.Tables.Add(Table_a);


    tblDataSet.Relations.Add("Relation1",
        Table_c.Columns["Number"], Table_a.Columns["Number"]);

    BindingSource bsC = new BindingSource();
    bsC.DataSource = tblDataSet;
    bsC.DataMember = "Table_c";

    BindingSource bsA = new BindingSource();
    bsA.DataSource = bsC;
    bsA.DataMember = "Relation1";

    table_cDataGridView.DataSource = bsC;
    table_aDataGridView.DataSource = bsA; 
}
Posted
Updated 29-Sep-15 3:05am
v2
Comments
[no name] 29-Sep-15 9:12am    
Hard to say, maybe changing the sequence will help?
1.) tblDataSet.Tables.Add(Table_a);
2.) tblDataSet.Tables.Add(Table_c);
Gya 29-Sep-15 9:28am    
If I do this, I get this error to "tblDataSet.Tables.Add(Table_a);": "DataTable already belongs to another DataSet."

It seems there some problem with variables you are using. There are two global table varaibles Table_c and Table_a, but you when you are filling through adapter, you are using tables from dataset, and when you are adding tables to another dataset here you are using that global varaibles (which do not have any value/object, are unassigned).
 
Share this answer
 
Comments
[no name] 29-Sep-15 9:31am    
That sounds quite reasonable, a 5.
If I use them local, I get this error
"column argument cannot be null.Parameter name: column",
to this line:
tblDataSet.Relations.Add(Relation1, Table_c.Columns["Number"], Table_a.Columns["Number"]);

If I don't declare them, and I use this.DBDataSet1.Table_c instead, I get "DataTable already belongs to another DataSet"
 
Share this answer
 
Comments
Richard Deeming 29-Sep-15 11:28am    
This is not a solution.

If you have a question or comment, use the "Have a Question or Comment?" button under the relevant solution.
If you want to update your question, use the "Improve question" button at the bottom of the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900