Loading an ADO Recordset into a DataSet
Số trang: 2
Loại file: pdf
Dung lượng: 12.59 KB
Lượt xem: 12
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
[ Team LiB ] Recipe 5.9 Loading an ADO Recordset into a DataSet Problem You want to convert an ADO Recordset generated within a legacy application to a DataSet so that you can use it in a .NET application. Solution Use COM interop or the Fill( ) method of the OLE DB data provider DataAdapter.
Nội dung trích xuất từ tài liệu:
Loading an ADO Recordset into a DataSet[ Team LiB ]Recipe 5.9 Loading an ADO Recordset into a DataSetProblemYou want to convert an ADO Recordset generated within a legacy application to aDataSet so that you can use it in a .NET application.SolutionUse COM interop or the Fill( ) method of the OLE DB data provider DataAdapter.Youll need a reference to the Primary Interop Assembly (PIA) for ADO provided in thefile ADODB.DLL. Select adodb from the .NET tab in Visual Studio .NETs AddReference Dialog.The sample code creates an ADO Recordset for the Orders table in Northwind. The Fill( )method of the OleDbDataAdapter is used to load the Recordset into a DataTable.The C# code is shown in Example 5-9.Example 5-9. File: AdoRecordsetForm.cs// Namespaces, variables, and constantsusing System;using System.Data;using System.Data.OleDb;// . . .// Open an ADO connection.ADODB.Connection conn = new ADODB.Connection( );conn.Open(Provider = SQLOLEDB;Data Source = (local); + Initial Catalog = northwind,sa,,0);// Create an ADO recordset.ADODB.Recordset rs = new ADODB.Recordset( );rs.Open(SELECT * FROM Orders, conn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);// Create and fill a dt from the ADO recordset.DataTable dt = new DataTable(Orders);(new OleDbDataAdapter( )).Fill(dt, rs);conn.Close( );// Bind the default view of the dt to the grid.dataGrid.DataSource = dt.DefaultView;DiscussionOne of the overloads of the OLE DB .NET DataAdapter.Fill( ) method accepts an ADORecordset or Record object. The COM component that returns an ADO Recordset orRecord object is consumed using COM interop.While the data can be loaded into a DataSet in this way, there is no way to reconcile thechanges made to the data in the DataSet with the data source underlying the ADO object.This must be explicitly handled.There is no FillSchema( ) method which allows the schema of an ADO Recordset to beretrieved into a DataSet.[ Team LiB ]
Nội dung trích xuất từ tài liệu:
Loading an ADO Recordset into a DataSet[ Team LiB ]Recipe 5.9 Loading an ADO Recordset into a DataSetProblemYou want to convert an ADO Recordset generated within a legacy application to aDataSet so that you can use it in a .NET application.SolutionUse COM interop or the Fill( ) method of the OLE DB data provider DataAdapter.Youll need a reference to the Primary Interop Assembly (PIA) for ADO provided in thefile ADODB.DLL. Select adodb from the .NET tab in Visual Studio .NETs AddReference Dialog.The sample code creates an ADO Recordset for the Orders table in Northwind. The Fill( )method of the OleDbDataAdapter is used to load the Recordset into a DataTable.The C# code is shown in Example 5-9.Example 5-9. File: AdoRecordsetForm.cs// Namespaces, variables, and constantsusing System;using System.Data;using System.Data.OleDb;// . . .// Open an ADO connection.ADODB.Connection conn = new ADODB.Connection( );conn.Open(Provider = SQLOLEDB;Data Source = (local); + Initial Catalog = northwind,sa,,0);// Create an ADO recordset.ADODB.Recordset rs = new ADODB.Recordset( );rs.Open(SELECT * FROM Orders, conn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);// Create and fill a dt from the ADO recordset.DataTable dt = new DataTable(Orders);(new OleDbDataAdapter( )).Fill(dt, rs);conn.Close( );// Bind the default view of the dt to the grid.dataGrid.DataSource = dt.DefaultView;DiscussionOne of the overloads of the OLE DB .NET DataAdapter.Fill( ) method accepts an ADORecordset or Record object. The COM component that returns an ADO Recordset orRecord object is consumed using COM interop.While the data can be loaded into a DataSet in this way, there is no way to reconcile thechanges made to the data in the DataSet with the data source underlying the ADO object.This must be explicitly handled.There is no FillSchema( ) method which allows the schema of an ADO Recordset to beretrieved into a DataSet.[ Team LiB ]
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình Oreilly Ado Dot Net Cookbook Ebook-Lib Loading an ADO Recordset into a DataSetTài liệu có liên quan:
-
52 trang 468 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 367 0 0 -
96 trang 334 0 0
-
74 trang 329 0 0
-
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 321 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 321 1 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 310 0 0 -
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 304 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 303 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 297 0 0