把数据增加到datatable的方法

作者:袖梨 2022-06-25

把数据增加到datatable的方法
向DataTable中添加一行数据

<%@Import namespace="System.Data" %>


<asp教程:DataGrid runat="server" id="datagrid" />

来自网络

手动插入一行数据

        DataSet ds = tTalent.GetAllInfo();
        DataRow dr = ds.Tables[0].NewRow();
        dr["id"] = 0;
        dr["aboutType"] = "常见问题";
        dr["contents"] = "";
        ds.Tables[0].Rows.Add(dr);
        this.dlTalent.DataSource = ds.Tables[0].DefaultView;
        this.dlTalent.DataBind();

插入一列数据

        DataTable dt = DBHelper.GetDataTable(sql);
        dt.Columns.Add("num", Type.GetType("System.Int32"));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["num"] = i + 1;
        }


DataTable tblDatas = newDataTable("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(newobject[]{null,"a","b","c"});
tblDatas.Rows.Add(newobject[] { 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" });

相关文章

精彩推荐