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 ("
"); response.write (Myrow [" ColumnName "]); Response.write " td>");} response.write (" tr>"); while (MyReader.Read ()) {response.write (" | |
" MyReader ["ID"]. TOSTRING () " td>"); response.write (" | " MyReader ["Title"]. TOSTRING () " TD>); Response.write (" TR> ");} response.write " table>"); 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)
|