<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
/////////////////////////////////////////////////// Web.config 설정부분 //////////////////////////////////////////////////////////////////
////<connectionStrings>
//// <add name="TestConnectionString" connectionString="Data Source=.;Initial Catalog=Test;User ID=sa;Password=sa"
//// providerName="System.Data.SqlClient" />
////</connectionStrings>
/////////////////////////////////////////////////// Web.config 설정부분 //////////////////////////////////////////////////////////////////
// SqlConnection 개체 생성
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString);
// SqlCommand 개체 생성
string strSql = "SELECT * From Member";
SqlCommand cmd = new SqlCommand(strSql, con);
// SqlDataReader 개체 생성
con.Open(); // Connection 개체 열기
SqlDataReader rd = cmd.ExecuteReader();
// SqlDataReader 개체를 GridView 컨트롤에 바인딩
GridView1.DataSource = rd;
GridView1.DataBind();
// SqlDataReader 개체 및 SqlConnection 개체 닫기
rd.Close();
con.Close();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>제목 없음</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>연결기반 SELECT 예제</h3>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////