本文介绍了我正在尝试在两个datagridviews之间形成关系父子,但我收到此错误:'table'参数不能为null。参数名称:table“。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我得到了这一行的错误:tblDataSet.Tables.Add(Table_c); 有谁知道如何解决它?在此先感谢。 这是代码: private DataTable Table_c; // Table_c从本地数据库导入 private DataTable Table_a; // Table_a从本地数据库导入 private DataSet tblDataSet; private void Form1_Load(对象 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; } 解决方案 您使用的变量似乎存在一些问题。有两个全局表变量Table_c和Table_a,但是当你通过适配器填充时,你正在使用数据集中的表,当你在这里将表添加到另一个数据集时,你正在使用那些全局变量(没有任何值/对象,未分配)。 如果我在本地使用它们,我会收到此错误 列参数不能为null。参数名称:column , 到此行: tblDataSet.Relations.Add(Relation1,Table_c.Columns [数字],Table_a.Columns [数字]); 如果我没有声明它们,我使用 this.DBDataSet1.Table_c 相反,我得到DataTable已经属于另一个DataSet 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:private DataTable Table_c; // Table_c is imported from a local databaseprivate DataTable Table_a; // Table_a is imported from a local databaseprivate 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; } 解决方案 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).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" 这篇关于我正在尝试在两个datagridviews之间形成关系父子,但我收到此错误:'table'参数不能为null。参数名称:table“。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 11:42