ADO.NET: SCHEMA information from Data table from DataReader

xiaoxiao2021-03-06  42

Source: Unknown Author: Unknown Recommended rating: Visits: 5

Using DataReader's getSchematable () method can get the structure information contained in the data table. This method returns a DataTable, and the COLUMNNAME attribute value of each row in the DataTable is a field name for the data table. SqlConnection Coredb = New SqlConnection (); Coredb.connectionstring = "Workstation ID = /" GQA-Eric-LV / "; packet size = 4096; Integrated Security = SSPI;" "Data Source = /" GQA-ERIC-LV / "; persist security info = False; initial catalog = coreDB"; string mySelectQuery = "SELECT ID, Title FROM myBBS order by id asc"; SqlCommand myCommand = new SqlCommand (mySelectQuery, coreDB); coreDB.Open (); SqlDataReader myReader = MyCommand.executeReader (); // Save the information defined by the database to the table Schematable: DataTable schematable = myReader.getschematable (); // Table Schematable's information about a field of database tables: Response.write ("

"); Foreach (DataRow Myrow In schement.rows) {response.write (" "); response.write ("
"); response.write (Myrow [" ColumnName "]); Response.write "");} response.write (""); while (MyReader.Read ()) {response.write ("
" MyReader ["ID"]. TOSTRING () ""); response.write (" " MyReader ["Title"]. TOSTRING () " ); Response.write (" ");} response.write ""); MyReader.close (); Coredb.close (); The result of the display is as shown in Figure: The use of SQLConnection, SqlCommand, DataReader is also exemplified.

转载请注明原文地址:https://www.9cbs.com/read-70407.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.047, SQL: 9