如何合并两个DataTable?
解决方案 »
- c#编程
- 大家好,我想问个Repeater调用自定义方法的问题
- 如何用C#实现用下载完成自动杀毒
- c#怎么判断系统是否已经IIS安装;还有如果IIS安装了,怎么判断服务是否启动
- 什么情况会出现这个异常?数据并发会吗?
- 拿出了我所有的分数了!!!新手关于启动画面的疑问,多线程,Timer的使用.
- winform程序开发如何做键盘按下任意的组合键
- 推荐一个报表控件 开源的 ( 除了水晶报表)
- 如何让Winform 中的大dataGrid 控件奇偶项的颜色有不同的颜色?
- 將全局變量dataset賦值給一個局部變量dataset,爲什麽對局部變量進行刪除會影響到全局變量?怎麼避免
- How to:实现在DataGird中关联表,并将关联后的内容作为DataGird的列
- 动态调用窗体问题
// Create a DataSet with one table, two columns, and ten rows.
DataSet ds = new DataSet("myDataSet");
DataTable t = new DataTable("Items"); // Add table to the DataSet
ds.Tables.Add(t); // Create and add two columns to the DataTable
DataColumn c1 = new DataColumn("id", Type.GetType("System.Int32"),"");
c1.AutoIncrement=true;
DataColumn c2 = new DataColumn("Item", Type.GetType("System.Int32"),"");
t.Columns.Add(c1);
t.Columns.Add(c2); // Set the primary key to the first column.
t.PrimaryKey = new DataColumn[1]{ c1 }; // Add RowChanged event handler for the table.
t.RowChanged+= new DataRowChangeEventHandler(Row_Changed); // Add ten rows.
for(int i = 0; i <10;i++){
DataRow r=t.NewRow();
r["Item"]= i;
t.Rows.Add(r);
} // Accept changes.
ds.AcceptChanges();
PrintValues(ds, "Original values"); // Create a second DataTable identical to the first, with
// one extra column using the Clone method.
DataTable t2 = t.Clone();
t2.Columns.Add("extra", typeof(string)); // Add two rows. Note that the id column can't be the
// same as existing rows in the DataSet table.
DataRow newRow;
newRow=t2.NewRow();
newRow["id"]= 12;
newRow["Item"]=555;
newRow["extra"]= "extra Column 1";
t2.Rows.Add(newRow); newRow=t2.NewRow();
newRow["id"]= 13;
newRow["Item"]=665;
newRow["extra"]= "extra Column 2";
t2.Rows.Add(newRow); // Merge the table into the DataSet.
Console.WriteLine("Merging");
ds.Merge(t2,false,MissingSchemaAction.Add);
PrintValues(ds, "Merged With Table, Schema Added");
}private void Row_Changed(object sender, DataRowChangeEventArgs e){
Console.WriteLine("Row Changed " + e.Action.ToString() + "\t" + e.Row.ItemArray[0]);
}private void PrintValues(DataSet ds, string label){
Console.WriteLine("\n" + label);
foreach(DataTable t in ds.Tables){
Console.WriteLine("TableName: " + t.TableName);
foreach(DataRow r in t.Rows){
foreach(DataColumn c in t.Columns){
Console.Write("\t " + r[c] );
}
Console.WriteLine();
}
}
}
将指定的 DataSet、DataTable 或 DataRow 对象的数组合并到当前的 DataSet 或 DataTable 中。重载列表
将 DataRow 对象数组合并到当前的 DataSet 中。[Visual Basic] Overloads Public Sub Merge(DataRow())
[C#] public void Merge(DataRow[]);
[C++] public: void Merge(DataRow*[]);
[JScript] public function Merge(DataRow[]);
将指定的 DataSet 及其架构合并到当前 DataSet 中。[Visual Basic] Overloads Public Sub Merge(DataSet)
[C#] public void Merge(DataSet);
[C++] public: void Merge(DataSet*);
[JScript] public function Merge(DataSet);
将指定的 DataTable 及其架构合并到当前 DataSet 中。[Visual Basic] Overloads Public Sub Merge(DataTable)
[C#] public void Merge(DataTable);
[C++] public: void Merge(DataTable*);
[JScript] public function Merge(DataTable);
将指定的 DataSet 及其架构合并到当前 DataSet 中,在此过程中,将根据给定的参数保留或放弃在此 DataSet 中进行的任何更改。[Visual Basic] Overloads Public Sub Merge(DataSet, Boolean)
[C#] public void Merge(DataSet, bool);
[C++] public: void Merge(DataSet*, bool);
[JScript] public function Merge(DataSet, Boolean);
将 DataRow 对象数组合并到当前的 DataSet 中,在此过程中,将根据给定的参数保留或放弃在 DataSet 中进行的更改并处理不兼容的架构。[Visual Basic] Overloads Public Sub Merge(DataRow(), Boolean, MissingSchemaAction)
[C#] public void Merge(DataRow[], bool, MissingSchemaAction);
[C++] public: void Merge(DataRow*[], bool, MissingSchemaAction);
[JScript] public function Merge(DataRow[], Boolean, MissingSchemaAction);
将指定的 DataSet 及其架构与当前的 DataSet 合并,在此过程中,将根据给定的参数保留或放弃在当前 DataSet 中的更改并处理不兼容的架构。[Visual Basic] Overloads Public Sub Merge(DataSet, Boolean, MissingSchemaAction)
[C#] public void Merge(DataSet, bool, MissingSchemaAction);
[C++] public: void Merge(DataSet*, bool, MissingSchemaAction);
[JScript] public function Merge(DataSet, Boolean, MissingSchemaAction);
将指定的 DataTable 及其架构合并到当前的 DataSet 中,在此过程中,将根据给定的参数保留或放弃在 DataSet 中进行的更改并处理不兼容的架构。[Visual Basic] Overloads Public Sub Merge(DataTable, Boolean, MissingSchemaAction)
[C#] public void Merge(DataTable, bool, MissingSchemaAction);
[C++] public: void Merge(DataTable*, bool, MissingSchemaAction);
[JScript] public function Merge(DataTable, Boolean, MissingSchemaAction);