제목 : 예제. SqlDataAdapter 클래스를 사용한 DataTable 채우기 2(C#)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%
SqlConnection objCon;
SqlCommand objCmd;
SqlDataAdapter objDa;
DataSet objDs;
objCon = new SqlConnection();
objCon.ConnectionString = "server=localhost;database=Pubs;user id=sa;password=1234";
objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "Select Top 5 * From Authors";
objCmd.CommandType = CommandType.Text;
objDa = new SqlDataAdapter();
objDa.SelectCommand = objCmd;
objDs = new DataSet();
objDa.Fill(objDs, "Authors");
foreach(DataRow objDr in objDs.Tables["Authors"].Rows)
{
Response.Write(objDr["au_lname"] + "<br>");
}
%>