Fork me on GitHub
public void createTable()
    {
        DataSet ds = new DataSet();
        using (DataTable dt = new DataTable("students"))
        {
            //创建列
            DataColumn dtc = new DataColumn("姓名",typeof(string));
            dt.Columns.Add(dtc);

            dtc = new DataColumn("性别",typeof(string));
            dt.Columns.Add(dtc);

            dtc = new DataColumn("电话",typeof(Int32));
            dt.Columns.Add(dtc);

            //添加数据到DataTable
            DataRow dr = dt.NewRow();
            dr["姓名"] = "张三";
            dr["性别"] = "";
            dr["电话"] = 54531;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
           
            dr["姓名"] = "李四";
            dr["性别"] = "";
            dr["电话"] = 5731;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
           
            dr["姓名"] = "王五";
            dr["电话"] = 5868451;
            dr["性别"] = "";
            dt.Rows.Add(dr);
            ds.Tables.Add(dt);
        }
    }

 

posted on 2013-10-22 21:48  lingfeng95  阅读(241)  评论(0编辑  收藏  举报