Close access to ASP. Net (7)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.