In the previous section, we spoke briefly about the application of the database, and we did not specify how the execution statements were used to display
Shown Oh, is to stay in this section of the talk. Here we have to understand datareader,dataset and dat
Agrid control, the DataGrid is the display control, everyone has to look at it related to the application, we don't shiver here, Da
Tareader and datasets can be used to store data content, but DataReader can only store the results of the query, Da
Taset is relatively complex, his function is very powerful, we step by step, this section is still not finished, we
This section only talk about its function of storing database, hehe, in order to and DataReader explanation.
Talk about the database, the first useful data to do, I have a random a database, named company, and then added a
A few numbers in.
DataReader
DataReader read the name to know that is to read the data, we can through the command of the Execute method, will
There are a lot of methods and properties to get the data stored in Datareader,datareader, which is often read, and I don't
If you want to talk 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)
{
Defining statements
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;
Fu and DataReader with the result
Mycommand.execute (out MyDataReader);
Bind the DataReader to the DataGrid
Show. Datasource=mydatareader;
Show. DataBind ();
Shut down
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