As before, write your own style layout first,
The second step is to create a commodity table in the database
The code is as follows:
CREATE TABLE [Shangping_info] ([shangping_id] INT PRIMARY KEY IDENTITY, [Shangping_name] CHAR ( -) not NULL, [shangping_content] CHAR ( -) not NULL, [Add_time] DATETIME) inserts into [Vip_user] VALUES ('Tangxuelong','[email protected]'INSERT into [Shangping_info] VALUES ('airconditioner','Air Conditioning', the-5- -)
The third step, start writing the background code binding data,
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;usingDAL;namespacemystore{ Public Partial classMain:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {DBHelper db=NewDBHelper ();//instantiation ofSqlConnection conn = db. Getcoon ();//Create a Connection object if(Conn. state = = ConnectionState.Open)//determine if the database is open{Conn. Close (); } conn. Open (); //Open Database stringsql ="select * FROM [Shangping_info]";//Query StatementsSqlDataAdapter da =NewSqlDataAdapter (Sql,conn);//querying data using DataAdapterDataSet ds =NewDataSet ();//Create a DataSet objectDa. Fill (DS);//populating data read by DataAdapter into a datasetGridview_shangping. DataSource = ds;//bind the data source of the GridView to a datasetgridview_shangping. DataBind (); Conn. Close (); Da. Dispose (); } }}
F5 ran up to see the data.