I am trying to add one DataColumn in two different DataTable, but it is giving me error and saying that "Column 'imgCount' already belongs to another DataTable". Can I do this? here is my code.
DataTable dtS = new DataTable();
DataTable dtF = new DataTable();
DataColumn imgCount = new DataColumn("imgCount",Type.GetType("System.Int32"));
imgCount.DefaultValue = 0;
dtS = dvSho.ToTable("shooters");
dtS.Columns.Add(imgCount);
dtF = dvFys.ToTable("fyshwick");
dtF.Columns.Add(imgCount);
You can not add a single column instance to the DataTables.
Create separate instances for the two tables.
DataColumn imgCount = new DataColumn("imgCount",Type.GetType("System.Int32"));
DataColumn imgCount2 = new DataColumn("imgCount",Type.GetType("System.Int32"));
dtS = dvSho.ToTable("shooters");
dtS.Columns.Add(imgCount);
dtF = dvFys.ToTable("fyshwick");
dtF.Columns.Add(imgCount2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.