两个表的结构是相同的,但是查出来的数据条数不同,
如table1 查出10条数据,table2 查出15条数据,怎样把两个DataTable和并成一个,请高手解答...
列是相同的,只是查出的数据数据条数不同
如table1 查出10条数据,table2 查出15条数据,怎样把两个DataTable和并成一个,请高手解答...
列是相同的,只是查出的数据数据条数不同
解决方案 »
- 谁有C#类似飞信局域网即时通讯的源代码,给兄弟个连接
- 为什么报错说错 说“Lib.Data.MessageInfo”并不包含“ToByte”的定义? E:\学习\Net\JSTX\Client\UserLogin
- vs2010发布网站出现了未将对象引用设置到对象的实例
- visual C#与c#到底什么区别
- .NET 2005 通过"添加数据源"向导手工添加DataSet数据源的问题.
- 现在正在做有关报告生成这一块,如何在窗体上显示一个报告生成的进度呢,求思路!
- 64位处理器兼容性问题。
- C#浏览器完善
- 高分求助 UP者有分 http://community.csdn.net/Expert/topic/3837/3837588.xml?temp=.653866
- 爬虫应该如何监控目标网页的改版?
- FtpWebRequest支持linux的FTP服务器吗?
- 关于SIM卡GPS功能
....
DataTable dt2 = new DataTable();
.....
dt2.Merge(dt1);
private static void DemonstrateMergeTable()
{
// Demonstrate merging, within and without
// preserving changes. // In this example, take these actions:
// 1. Create a DataTable (table1) and fill the table with data.
// 2. Create a copy of table1, and modify its data (modifiedTable).
// 3. Modify data in table1.
// 4. Make a copy of table1 (table1Copy).
// 5. Merge the data from modifiedTable into table1 and table1Copy,
// showing the difference between setting the preserveChanges
// parameter to true and false. // Create a new DataTable.
DataTable table1 = new DataTable("Items"); // Add two columns to the table:
DataColumn column = new DataColumn("id", typeof(System.Int32));
column.AutoIncrement = true;
table1.Columns.Add(column); column = new DataColumn("item", typeof(System.String));
table1.Columns.Add(column); // Set primary key column.
table1.PrimaryKey = new DataColumn[] { table1.Columns[0] }; // Add some rows.
DataRow row;
for (int i = 0; i <= 3; i++)
{
row = table1.NewRow();
row["item"] = "Item " + i;
table1.Rows.Add(row);
} // Accept changes.
table1.AcceptChanges();
PrintValues(table1, "Original values"); // Using the same schema as the original table,
// modify the data for later merge.
DataTable modifiedTable = table1.Copy();
foreach (DataRow rowModified in modifiedTable.Rows)
{
rowModified["item"] = rowModified["item"].ToString()
+ " modified";
}
modifiedTable.AcceptChanges(); // Change row values, and add a new row:
table1.Rows[0]["item"] = "new Item 0";
table1.Rows[1]["item"] = "new Item 1"; row = table1.NewRow();
row["id"] = 4;
row["item"] = "Item 4";
table1.Rows.Add(row); // Get a copy of the modified data:
DataTable table1Copy = table1.Copy();
PrintValues(table1, "Modified and new Values");
PrintValues(modifiedTable, "Data to be merged into table1"); // Merge new data into the modified data.
table1.Merge(modifiedTable, true);
PrintValues(table1, "Merged data (preserve changes)"); table1Copy.Merge(modifiedTable, false);
PrintValues(modifiedTable, "Merged data (don't preserve changes)");
}
private static void PrintValues(DataTable table, string label)
{
// Display the values in the supplied DataTable:
Console.WriteLine(label);
foreach (DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
Console.Write("\t{0}", row[column, DataRowVersion.Current]);
}
Console.WriteLine();
}
}
那就直接插入到DataTable中? string为空,int为0?