111 (
The First Data connection tool with VS comes in.
1. First create a blank aspx page, and find "data--gridview" in the toolbox to add a GridView. Add to the right there's a little arrow. New data source-New connection
The server name is the name of the server when you log in to the Sqlsever interface, either Windows Authentication or SQL Sever authentication is available, but Windows seems to have limitations.
After you select the database name and then continue to the next step,
Here's a good table to specify,
And then it's ready.
The second type, with code configuration,
1, first create a new ASPX page, in the corresponding. cs file namespace to add some references,
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.Security;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
Using System.Data;
And then add the code inside Page_Load.
protected void Page_Load (object sender, EventArgs e)
{
SqlConnection Sqlcon = new SqlConnection ();
sqlcon.connectionstring = "server=xxxx;database=xxx;uid=user;pwd=123";
String sqlstr = "Select *from jwdtable";
SqlDataAdapter da = new SqlDataAdapter (Sqlstr, Sqlcon);
DataSet ds=new DataSet ();
Da. Fill (ds, "jwdtable");
Response.Write (DS);
Datalist1.datasource = ds;
Bind data to the DataList1 control
Datalist1.databind ();
}
Then add a DataList to the ASPX page
Select Edit Template, you can enter some name items, and then add a label inside to bind the database inside the column name
Add a label to the right arrow and select DataBindings
Code expression there fill in eval ("Column name Inside Database")
ASP two methods connect SQL Sever and display