'table'参数不能为null。参数名称:表格

时间:2015-09-29 08:59:56

标签: c# datagridview

我正在尝试在两个datagridviews之间形成一个关系亲子,但我收到了这个错误:

  

'table'参数不能为null。参数名称:table“,到此行:

{{1}}

有谁知道我该如何解决?提前谢谢。

这是代码:

{{1}}

1 个答案:

答案 0 :(得分:0)

试试这个:

private DataTable Table_c;
private DataTable Table_a;
private DataSet tblDataSet;

private void Form1_Load(object sender, EventArgs e)
{
    Table_a = this.table_aTableAdapter1.GetData();
    Table_c = this.table_cTableAdapter.GetData();

    tblDataSet = new DataSet();
    tblDataSet.Tables.Add(Table_a);
    tblDataSet.Tables.Add(Table_c);    
    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; 
}