zoukankan      html  css  js  c++  java
  • DataTable添加行的方法

    方法一:

    DataTable tblDatas = new DataTable("Datas");
    DataColumn dc = null;
    dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
    dc.AutoIncrement = true;//自动增加
    dc.AutoIncrementSeed = 1;//起始为1
    dc.AutoIncrementStep = 1;//步长为1
    dc.AllowDBNull = false;//

    dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
    dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
    dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));

    DataRow newRow;
    newRow = tblDatas.NewRow();
    newRow["Product"] = "水果刀";
    newRow["Version"] = "2.0";
    newRow["Description"] = "打架专用";
    tblDatas.Rows.Add(newRow);

    newRow = tblDatas.NewRow();
    newRow["Product"] = "折叠凳";
    newRow["Version"] = "3.0";
    newRow["Description"] = "行走江湖七武器之一";
    tblDatas.Rows.Add(newRow);

    方法二:

    DataTable tblDatas = new DataTable("Datas");
    tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
    tblDatas.Columns[0].AutoIncrement = true;
    tblDatas.Columns[0].AutoIncrementSeed = 1;
    tblDatas.Columns[0].AutoIncrementStep = 1;

    tblDatas.Columns.Add("Product", Type.GetType("System.String"));
    tblDatas.Columns.Add("Version", Type.GetType("System.String"));
    tblDatas.Columns.Add("Description", Type.GetType("System.String"));

    tblDatas.Rows.Add(new object[]{null,"a","b","c"});
    tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
    tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
    tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
    tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });

  • 相关阅读:
    更快的datetime string to python datetime转换模块 ciso8601
    华为新员工入职培训计划曝光!你留不住员工的原因就在这! zz
    在vmware中安装macos系统 vm12 osx10.11 or higher
    vmware for linux (centos65) 卸载相关
    第八章多态
    第七章 复用类
    第六章 访问权限控制
    Think in Java 第四 五 章
    Think in Java 第三章操作符
    Thank in Java
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175842.html
Copyright © 2011-2022 走看看