Clear移除表中所有行来清除任何数据的DataSet

Clone赋值该DataSet的结构但不复制数据

Copy赋值DataSet的结构和数据

Dispose释放DataSet对象

Equals确定两个DataSet对象是否相同

Merge指定的DataSet DataTable或DataRow对象的数组合到当前的DataSet或DataTable中

Reset将DataSet重置为初始状态

  class Program
{
public void outvalue(DataSet ds)
{
foreach (DataTable outdtb in ds.Tables)
{
Console.WriteLine(outdtb.TableName);
foreach (DataRow outdrw in outdtb.Rows)
{
foreach (DataColumn outdcl in outdtb.Columns)
{
Console.Write(outdrw[outdcl]+"\t"); }
Console.WriteLine();
} } } static void Main(string[] args)
{
try
{
DataSet ds = new DataSet("csharp001");
DataTable dtb = new DataTable("mytable001");
ds.Tables.Add(dtb); DataColumn mycl0 = new DataColumn("id", Type.GetType("System.Int32"));
DataColumn mycl1 = new DataColumn("name",Type.GetType("System.String"));
DataColumn mycl2 = new DataColumn("deparment", Type.GetType("System.String"));
dtb.Columns.Add(mycl0);
dtb.Columns.Add(mycl1);
dtb.Columns.Add(mycl2); string[,] mystr = { { "张三", "销售部" }, { "李四", "人事部" }, { "王五", "网络部" }, { "赵六", "开发部" }, { "刘奇", "研发部" }, { "周八", "市场部" } };
for (int i = ; i < mystr.Length/; i++)
{
DataRow drw = dtb.NewRow();
dtb.Rows.Add(drw);
drw[] = i;
drw[]=mystr[i,];
drw[]=mystr[i,];
}
Program p = new Program();
p.outvalue(ds); DataTable mydt002 = dtb.Clone(); //mydt001de 的表克隆给mydt002 Console.WriteLine("\t","克隆后的表"); DataRow row01 = dtb.NewRow();
mydt002.Rows.Add(new object[]{,"杜九","开发部"}); ds.Merge(mydt002); //将mydt表 合并到dataset数据集中 p.outvalue(ds); Console.ReadKey(); } catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString()); }
finally
{ }
} }
}
05-11 19:44