TAILIEUCHUNG - Mapping Table and Column Names Between the Data Source and DataSet

[ Team LiB ] Recipe Mapping Table and Column Names Between the Data Source and DataSet Problem You want to control the names assigned to tables and columns when you fill a DataSet using a DataAdapter. | Team LiB Recipe Mapping Table and Column Names Between the Data Source and DataSet Problem You want to control the names assigned to tables and columns when you fill a DataSet using a DataAdapter. Solution Use DataTableMapping and DataColumnMapping objects to map the names of database tables and columns in the data source to different names in a DataSet when using a DataAdapter. The sample code defines a SQL statement to retrieve the CategorylD CategoryName and Description columns from the Categories table in Northwind. A DataAdapter is created with a DataTableMapping object to map the database table name Categories to the name tblmapCategories in the DataSet. Three DataColumnMapping objects are created to map the database column names to different names in the table in the DataSet. The DataAdapter is used to fill a new DataSet. Finally the default view of the mapped Categories table is bound to the data grid on the form. The C code is shown in Example 2-21. Example 2-21. File Namespaces variables and constants using System using using using using . . . Create the DataAdapter. String sqlText SELECT CategorylD CategoryName Description FROM Categories SqlDataAdapter da new SqlDataAdapter sqlText Sql_ConnectString II Create the table mapping to map the default table name Table . DataTableMapping dtm Table tblmapCategories II Create the column mappings for the Categories table. CategoryID colmapCategorylD CategoryName colmapCategoryName Description colmapDescription II Create the DataSet and fill. DataSet ds new DataSet ds II Retrieve and display the mapped name of the table as grid caption. TableName 0 .ToString II Bind the default view of the Categories table to the grid. .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.