简体   繁体   English

如何将数据插入数据集

[英]how to insert data to dataset

i have this making table:我有这个制作表:

DataTable WorkTbl()
        {
            DataTable Work= new DataTable("Work"); //Table Name
            DataColumn MAC = new DataColumn("MAC", typeof(string));
            DataColumn ID_OLD = new DataColumn("ID_OLD", typeof(string));

            Work.Columns.Add(MAC);
            Work.Columns.Add(ID_OLD);
            return Work;
        }

how to insert data to this table and how to convert this table to Dataset?如何将数据插入此表以及如何将此表转换为数据集?

thanks in advance提前致谢

From MSDN:来自 MSDN:

DataRow workRow = workTable.NewRow();

You then can manipulate the newly added row using an index or the column name, as shown in the following example.然后,您可以使用索引或列名来操作新添加的行,如下例所示。

workRow["CustLName"] = "Smith";
workRow[1] = "Smith";


DataSet customerOrders = new DataSet("CustomerOrders");

DataTable ordersTable = customerOrders.Tables.Add("Orders");

DataColumn pkOrderID = 
    ordersTable.Columns.Add("OrderID", typeof(Int32));
ordersTable.Columns.Add("OrderQuantity", typeof(Int32));
ordersTable.Columns.Add("CompanyName", typeof(string));

ordersTable.PrimaryKey = new DataColumn[] { pkOrderID };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM