In the previous section, we briefly talked about the application of the database, but we did not specifically describe how to execute statements for explicit
. Well, I will leave it in this chapter. Here, we must know about DataReader, DataSet, and Dat.
The aGrid control. The DataGrid is a display control. You can view its related applications on your own.
Both taReader and DataSet can be used to store data content, but DataReader can only store query results, Da
TaSet is much more complicated and has powerful functions. We can't finish this section step by step.
This section only describes the database storage function.
Let's talk about the database. First of all, we need to use useful data. I just created a database named Company and added it.
Several data entries
DataReader
DataReader can read the data by reading the name. We can use the Execute method of Command
The obtained data is stored in DataReader. DataReader has many methods and attributes and is commonly used for Read. Here I do not
I want to talk about it more. Let's take a look at its specific application first.
<% @ Page Language = "C #" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. SQL" %>
<Script Language = "C #" Runat = "Server">
Public void Page_Load (Object src, EventArgs e)
{
// Define the statement
String mySelectQuery = "SELECT * from Company ";
String myConnString = "server = localhost; uid = sa; pwd = 123456; database = aspcn ";
// Join
SQLConnection myConnection = new SQLConnection (myConnString );
SQLCommand myCommand = new SQLCommand (mySelectQuery, myConnection );
MyConnection. Open ();
// Define DataReader
SQLDataReader myDataReader;
// Associate DataReader with the result
MyCommand. Execute (out myDataReader );
// Bind the DataReader with the DataGrid
Show. DataSource = myDataReader;
Show. DataBind ();
// Close