Exporting the Results of a Query as a String

[ Team LiB ] Recipe Exporting the Results of a Query as a String Problem You need to export the results of a query to a string in a manner similar to the GetString( ) method of the ADO Recordset. Solution Write a routine to mimic the functionality of the ADO Recordset's GetString( ) method. | Team LiB Recipe Exporting the Results of a Query as a String Problem You need to export the results of a query to a string in a manner similar to the GetString method of the ADO Recordset. Solution Write a routine to mimic the functionality of the ADO Recordset s GetString method. The sample code contains an event handler and a method Go Sets up the sample by creating a DataTable containing the Orders table from Northwind. The GetString method in this solution is called to convert the DataTable into a string similar to one that is generated by the GetString method of the ADO Recordset. The string is displayed in a text box on the form. GetString This method mimics the functionality of the GetString method of the ADO Recordset. The method iterates over the collection of rows and columns in the table appending the field values to a string. Null values are replaced as specified and column and row delimiters are applied. The C code is shown in Example 5-13. Example 5-13. File Namespaces variables and constants using System using using using using Table name constants private const String ORDERS_TABLE Orders . . . private void goButton_Click object sender e Fill the Order table. SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders S ql_ConnectString DataTable dt new DataTable ORDERS_TABLE dt Call method to convert the DataTable to a string. GetString dt -1 null null null private String GetString DataTable dt int numRows String columnDelimiter String rowDelimiter String nullExpr if numRows 0 Negative number of rows returns all rows numRows else Set number of rows to the lesser of the user entered number of rows and the number of rows in the table. numRows numRows Column delimiter defaults to TAB if columnDelimiter null columnDelimiter t Row delimiter

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
272    23    1    01-12-2024
15    22    4    01-12-2024
Đã 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.