tailieunhanh - Copying Rows from One DataTable to Another

[ Team LiB ] Recipe Copying Rows from One DataTable to Another Problem You have records in a DataTable that you need to copy to another DataTable. Solution Use the ImportRow( ) method of the DataTable to copy DataRow objects from one DataTable to another. | Team LiB Recipe Copying Rows from One DataTable to Another Problem You have records in a DataTable that you need to copy to another DataTable. Solution Use the ImportRow method of the DataTable to copy DataRow objects from one DataTable to another. Three techniques for selecting records to copy are demonstrated in the following example Use the Rows property to access rows in the DataRowCollection of the DataTable using the row index. Use the Select method of the DataTable. Use the RowFilter property of a DataView for the DataTable. The sample code creates a source DataTable containing the Orders table from Northwind. A second empty target DataTable is created with the same schema. One of the three techniques as specified by the user is used to copy records from the source table to the target table. The C code is shown in Example 5-1. Example 5-1. File Namespaces variables and constants using System using using using Table name constants private const String ORDERS_TABLE Orders Field name constants private const String ORDERID_FIELD OrderlD . . . Fill the source table with schema and data. SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders Sql_ConnectString DataTable dt new DataTable ORDERS_TABLE dt dt Clone the schema to the copy table. DataTable dtCopy if Use ImportRow method to import the first three rows. for int i 0 i 3 i i else if Copy using result of Select method. foreach DataRow row in ORDERID_FIELD 10300 row else if Copy using result of filtered DataView. DataView categoryView ORDERID_FIELD 10300 AND ORDERID_FIELD 10400 for int i 0 i i categoryView i .Row Bind the default .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.