[Reserved] C # manually add a row of data to the end of the DataTable

During operation Datatable data variables in C #, the need to manually add variables to the end of the DataTable row of data, such as a practical example, we do data report, you may need to add a summary row DataRow data as recorded in the last line, At this point you need to manually add data to a DataTable variable. To add a DataTable variable data is mainly used a method to Add the DataTable Rows property variables.

Firstly, we have the Demo Datatable variable dataDt configuration information contained in the table 3, respectively, Name, Id, Memo. Due to business requirements need to remove the last one Memo.

To the above-described variable dataDt DataTable new row of data, the data values: Name = "John Doe", Id = 4, Memo = "added subsequently." Use the following program statement:

    DataRow newRow = dataDt.NewRow();
    newRow["Name"] = "李四";
    newRow["Id"] = 22;
    newRow["Memo"] = "后续新增";

  dataDt.Rows.Add(newRow);

In the above statement, the new instantiation needs DataRow object produced by the method of the DataTable NewRow, New not directly an object generated by the object Datable NewRow method DataRow same internal structure, such as column names like structure and order.

 

Note: The text reproduced from personal bloggers station IT technology small fun house , the original link for the C # manually add a new row to the DataTable technical data _IT small house at the end of interest .

Bloggers personal technology exchange group: 960 640 092, blogger micro-channel public numbers are as follows:

Guess you like

Origin www.cnblogs.com/xu-yi/p/11246427.html