创建DataSet

private DataSet CreatTable()
        {
            //创建一个Table 和 DataSet
            DataTable table = new DataTable();
            DataSet ds = new DataSet();
            //创建一个列
            DataColumn column1 = new DataColumn();
            column1.DataType = System.Type.GetType("System.String");
            column1.ColumnName = "Periord";
            //创建一个列
            DataColumn column2 = new DataColumn();
            column2.DataType = System.Type.GetType("System.Int32");
            column2.ColumnName = "Total";
            //
            //把列添加进去
            table.Columns.Add(column1);
            table.Columns.Add(column2);
            //创建一个行
            DataRow row1 = table.NewRow();
            row1["Periord"] = "Monday";
            row1["Total"] = 0;


            DataRow row2 = table.NewRow();
            row2["Periord"] = "Tuesday";
            row2["Total"] = 0;


            DataRow row3 = table.NewRow();
            row3["Periord"] = "Wednesday";
            row3["Total"] = 0;


            DataRow row4 = table.NewRow();
            row4["Periord"] = "Thursday";
            row4["Total"] = 0;


            DataRow row5 = table.NewRow();
            row5["Periord"] = "Friday";
            row5["Total"] = 0;


            DataRow row6 = table.NewRow();
            row6["Periord"] = "Saturday";
            row6["Total"] = 0;


            DataRow row7 = table.NewRow();
            row7["Periord"] = "Sunday";
            row7["Total"] = 0;
            //把行添加进去
            table.Rows.Add(row1);
            table.Rows.Add(row2);
            table.Rows.Add(row3);
            table.Rows.Add(row4);
            table.Rows.Add(row5);
            table.Rows.Add(row6);
            table.Rows.Add(row7);
            //把 Table添加到 DataSet 里面去
            ds.Tables.Add(table);
            return ds;
        }

你可能感兴趣的:(创建DataSet)