Đang chuẩn bị liên kết để tải về tài liệu:
Exporting the Results of a Query as a String

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

[ Team LiB ] Recipe 5.11 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 5.11 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 Button.Click 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 AdoGetStringForm.es Namespaces variables and constants using System using System.Configuration using System.Text using System.Data using System.Data.SqlClient Table name constants private const String ORDERS_TABLE Orders . . . private void goButton_Click object sender System.EventArgs e Fill the Order table. SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders ConfigurationSettings.AppSettings S ql_ConnectString DataTable dt new DataTable ORDERS_TABLE da.Fill dt Call method to convert the DataTable to a string. resultTextBox.Text 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 dt.Rows.Count else Set number of rows to the lesser of the user entered number of rows and the number of rows in the table. numRows Math.Max numRows dt.Rows.Count Column delimiter defaults to TAB if columnDelimiter null columnDelimiter t Row delimiter

TÀI LIỆU LIÊN QUAN
Đã 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.