블로그 이미지
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. 15:02 .Net Project/ADO.NET 3.5
반응형
3 종류 이용한 메모리상의 데이터 베이스 가져오는 방법
- DataSet
은 데이터 소스에서 검색한 메모리 내의 데이터 캐시이며 ADO.NET 아키텍처 
  의 주요 구성 요소입니다.
- DataTable 
   DataTable
은 ADO.NET 라이브러리의 중심 개체입니다.
    DataTable을 사용하는 다른 개체에는 DataSetDataView가 포함됩니다
- Data View : The following example creates a simple ListBox and a Button

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

public partial class Category_FrmDataView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DisplayData();
        }
    }
    private void DisplayData()
    {
       //커넥션
        SqlConnection con = new SqlConnection
                   (ConfigurationManager.ConnectionStrings
                    ["ConnectionString"].ConnectionString);

        con.Open();
       
        //커맨드
        SqlCommand cmd = new SqlCommand
                     ("Select *From Products", con);
        //어댑터
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;

        DataSet ds = new DataSet();
        da.Fill (ds,"Products");

        //출력
        this.ctlProductList1.DataSource = ds; //[1]데이터셋
        this.ctlProductList1.DataBind();

        DataTable dt = ds.Tables["Products"]; //[2]데이터테이블
        this.ctlProductList2.DataSource = dt;
        this.ctlProductList2.DataBind();

        DataView dv = ds.Tables[0].DefaultView; //[3]데이터뷰
        this.ctlProductList3.DataSource = dv;
        this.ctlProductList3.DataBind();
    }
}



반응형
posted by Magic_kit