블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 9. 28. 14:04 .Net Project/ADO.NET 3.5
반응형

- DataSet : 메모리상의 데이터 베이스, 즉, DB에 있는 한 두개의 테이블을 읽어서
               DataSet 개체에 보관에 놓으면, 마치 물리적인 DB를 메모리에 두고,
               이를 사용해서 손쉽게 DB 입출력 기능을 구현 할 수 있는 막강한
               클래스

- Create a typed TableAdapter object and invoke the fill method

- Create an untyped DataAdapter Object, configur it, and then
   invoke the Fill metod

- SqlDataAdapter Data Display

- 데이터 출력 
   데이터 리더 : SqlConnection -> SqlCommand - > ExecuteReader()
                     -> SqlDataReader -> GridView
   데이터 셋 : SqlConnection -> SqlCommand -> SqlDataAdapter ->
                  ->Fill() -> DataSet -> GridView

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Category_FrmDataset : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) //처음 로드시에만 데이터 읽어서 바인딩
        {
            DisplayData();
        }
    }

    private void DisplayData()
    {
        using (SqlConnection con = new SqlConnection
                  (ConfigurationManager.ConnectionStrings
                   ["ConnectionString"].ConnectionString))
        {
            con.Open();

            SqlCommand cmd = new SqlCommand
                                ("Select *From Categories", con);
           
            //[!]SqlDataAdapter 클래스 인스턴스 생성
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;

            //[2]Dataset 클래스의 인스턴스
            DataSet ds = new DataSet();
           
            //[3]da.fill()메서드로 데이터 셋 채우
            da.Fill(ds, "Categories");

            //[4]GridVies에 바인딩
            ctlCategoryList.DataSource = ds;
            ctlCategoryList.DataBind();
        }
    }
}





반응형
posted by Magic_kit