博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

新建表添加新行

Posted on 2009-03-21 16:50  Aimee  阅读(125)  评论(0)    收藏  举报

//新建表
   DataTable dt=new DataTable();

   //定义表结构
   dt.Columns.Add("Id",typeof(System.Int32));
   dt.Columns.Add("Code",typeof(System.String));
   dt.Columns.Add("Name",typeof(System.String));

//添加新行
   for(int i=0;i<=3;i++)
   {
    DataRow dr=dt.NewRow();
    dr[0]=i;
    dr[1]="s"+i;
    dr[2]="sic"+i;
    dt.Rows.Add(dr);
   }