제목 : 예제. SqlDataReader 클래스를 사용한 Select문(C#)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%
SqlConnection objCon;
SqlCommand objCmd;
SqlDataReader objDr;
objCon = new SqlConnection();
objCmd = new SqlCommand();
string strCon = "server=localhost;database=dotnet;user id=dotnet;password=dotnet";
objCon.ConnectionString = strCon;
objCon.Open();
objCmd.Connection = objCon;
string strSql = "Select * From CSharpTest";
objCmd.CommandText = strSql;
objCmd.CommandType = CommandType.Text;
objDr = objCmd.ExecuteReader();
while(objDr.Read())
{
Response.Write(objDr["Num"].ToString() + ", " + objDr[1].ToString() + "<br>");
}
objDr.Close();
objCon.Close();
%>