Read the other People's blog, personal summary, there are errors please point out
1. Establish database Connection object
2, set up Database query object (increase and deletion of search)
3. Set up DataSet data Table object to save data and to realize disconnection
4. Set up Database Operation object
5. Get the connection string used to connect to the database by Conn object
6. Initialize the Query object
7. Operation of SQL statement by database operation Object
8. Initialize the DataSet object
9. Open the connection, get the data, close the connection
10. Throw an exception
protected Sqlconnection Conn;
Protected SqlDataAdapter da;
protected DataSet ds;
protected DataCommand Comm;
protected void Page_Load (object sender, EventArgs e)
{
Conn=new SqlConnection ("Data source=localhost;initial catalog=nd_data; User Id=sa; Password=aaaaaa ");//Fetch the connection string while establishing the connection
Da= New SqlDataAdapter ();//Initialize Query object
Da. selectcommand= New SqlCommand ("Select Name,id from xs Order by Id,name DESC", conn); database operation with a query ID and name
ds= new DataSet (); Initialize DataSet object
Try
{
Conn. Open ();//Opening connection
Da. Fill (ds, "abs");//Get the data and store it in a table named "ABS"
Conn. Close ();//Closed connection
}
catch (SqlException E1)//error handling
{
Response.Write (E1. ToString ());
}
Data Display phase:
PagedDataSource objpds= New PagedDataSource ();//Create a data source object that acts on the control
objpds.datasource= ds. Tables["ABS"]. defaultview;//the "ABS" table that was saved before passing in
Datalistname.datasource= objpds;//A data source object into the DataList control
Datalistname.databind ();//datalist control displays data information
Foreground data Display method:
<itemtemplate>//datalist Data Control Templates
<asp:label id= "Lbnwes" runat= "server" text= ' <% #Eval ("id")%> ' ></asp:label>//display ID
<asp:label id= "Lbtime" runat= "server" text= ' <% #Eval ("name")%> ' ></asp:label>//display name
</ItemTemplate>
ASP. NET database connection process