ASP two methods connect SQL Sever and display

Source: Internet
Author: User

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

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.