zoukankan      html  css  js  c++  java
  • DataSet常用简单方法

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

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

    Copy赋值DataSet的结构和数据

    Dispose释放DataSet对象

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

    Merge指定的DataSet DataTableDataRow对象的数组合到当前的DataSetDataTable

    ResetDataSet重置为初始状态

      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]+"	");
                            
                        }
                        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 = 0; i < mystr.Length/2; i++)
                    {
                        DataRow drw = dtb.NewRow();
                        dtb.Rows.Add(drw);
                        drw[0] = i;
                        drw[1]=mystr[i,0];
                        drw[2]=mystr[i,1];
                    }
                    Program p = new Program();
                    p.outvalue(ds);
    
                    DataTable mydt002 = dtb.Clone();          //mydt001de 的表克隆给mydt002
    
                    Console.WriteLine("	","克隆后的表");
    
                    DataRow row01 = dtb.NewRow();
                    mydt002.Rows.Add(new object[]{6,"杜九","开发部"});
    
                    ds.Merge(mydt002);  //将mydt表 合并到dataset数据集中
    
                    p.outvalue(ds);
    
    
                    Console.ReadKey();    
                     
                }
                    
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());
    
                }
                finally
                {
                    
                }
            }
    
        }
    }
  • 相关阅读:
    cors
    js 离开页面
    移动端 touch
    eclipse
    java获取classpath以外的路径
    Javascript类型转换的规则
    myeclipse开发安装C++
    MyEclipse10中配置开发Python所需要的PyDev 绝对靠谱 不忽悠!
    POI生成EXCEL,公式不自动执行的有关问题
    POI中设置Excel单元格格式样式(居中,字体,边框等)
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8648471.html
Copyright © 2011-2022 走看看