• 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" });

  • 相关阅读:
    C struct 中字节对齐问题(转)
    蚁群算法,PSO算法以及两种算法可以融合的几种方法
    遗传及蚁群算法
    ListBox FAQ常用问题
    关于C#中ListBox控件重绘Item项
    创业艰难,问题多多
    asp.net客户端脚本验证小技巧
    防止ASP.NET按钮多次提交的办法
    鼠标点到文本框时的提示信息
    枚举的转换
  • 原文地址:https://www.cnblogs.com/hulang/p/1932725.html
Copyright © 2020-2023  润新知