asp.net in the previous section, we simply talked about the application of the database, and we did not specify how the execution statement is used for the explicit
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.
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
Mydatareader.close ();
Myconnection.close ();
After these two steps are completed, we store the results of the execution into the DataReader.
In the end we bind it to the DataGrid control, and if we don't understand what the bundle is, look at the
Article.
Appears as follows: ID Name age Sex wage
1 Flying Knife 20 male 1400
2 Zhang 323 male 5000
3 Lee 447 Male 7786
4 King 520 Male 6788
5 Miaocuihua 30 Female 45676
6 Fangshiyu 20 Male 4656
Also tell everyone that if we need to get DataReader store the value of a particular field can use mydatareader[
"FieldName"] a similar approach to getting the following is a simple example
Wow, this is a difficult thing to understand for beginners. What's the best way to say it? We can look at the dataset.
into a no-connection recordset (this should be familiar to everyone). Data is stored in the dataset, and this is like
is a database in which tables are present, columns (Columns), associations (relationships), constraints (cons
Trains) and data. This is not the same as the database, but he is not a database (how to say the more confused
We can manipulate the data in the dataset (add, delete, update), and then submit it to the database
to operate. And the data in the dataset can come not only from the database, but also from XML and other data,
Even user input can be stored directly into the dataset
We only talk about the dataset for the role of data, hehe, but also just the display of data. Other applications, the next
Let's take a look at some examples first.
The result shown above is the same as the previous one, so let's explain the code
Here we use the DataSetCommand, we just need to pass its FillDataSet method to query the table Co
The results of the mpany are stored in the dataset, and the specific methods of operation are:
The future is tied up, there is nothing to say. Just to be aware that the dataset is its DataView and DA
Tagrid for bind, which I have already said in the previous article. Do not understand the people can turn to look at the front,
Look at the source program a lot.
In addition, we can add query results from multiple tables to a dataset, and these results can be connection without
The same, this realization is very simple, you can do it yourself
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