Blog Content

  • 17.ADO.NET - DataView

    Category ASP.NET on 2009. 9. 28. 15:03

    DB의 View와 같은 역할 정렬, 필터링, 검색, 편집 및 탐색을 위해 데이터 바인딩할 수 있는 DataTable의 사용자 지정 뷰 FrmDataView.aspx 상품 리스트 출력 FrmDataView.aspx.cs 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..

    Read more
  • 16.ADO.NET - DataTable

    Category ASP.NET on 2009. 9. 28. 14:21

    메모리에 있는 데이터로 구성된 하나의 테이블 메모리상의 테이블, 즉 DB의 Table개체와 일대일로 매핑할 수 있는 그릇(클래스) Rows와 Columns를 가짐 Test 데이터 베이스에 테이블을 추가 하고 설계합니다. Products 테이블 설계 값 입력하기 Insert into Products values('좋은컴퓨터') Insert into Products values('좋은책') Insert into Products values('좋은소프트웨어') Insert into Products values('최고급컴퓨터') select *from products FrmDataTable.aspx 카테고리 상품 FrmDataTable.aspx.cs protected void Page_Load(object se..

    Read more
  • 15.ADO.NET - DataSet

    Category ASP.NET on 2009. 9. 28. 13:58

    메모리상의 데이터베이스. 데이터 캐시 즉, DB에 있는 한두개의 테이블을 읽어서 DataSet 개체에 보관해 놓으면, 마치 물리적인 DB를 메모리에 두고, 이를 사용해서 손쉽게 DB 입출력 기능을 구현할 수 있는 막강한 클래스 테이블 정보를 그대로 컴퓨터 메모리 상으로 가져옴 한 개 이상의 테이블을 담아 둘 수 있는 큰 그릇 제네릭 클래스는 테이블 하나만 담을 수 있는 반면, 데이터셋은 테이블 여러개 담을 수 있다. 무겁지만 활용도 높고 사용이 편리 FrmDataSet.aspx FrmDataSet.aspx.cs protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) // 처음 로드시에만 데이터 읽어서 바인딩 { Displa..

    Read more
  • 14.ADO.NET - Transaction

    Category ASP.NET on 2009. 9. 28. 12:14

    데이터베이스를 통해서 테이블의 값을 수정 및 삭제하는 예제입니다. FrmTransaction.aspx FrmTransaction.aspx.cs protected void btnCommand_Click(object sender, EventArgs e) { string updateQuery = "Update Categories Set CategoryName = '컴퓨터' Where Num = 2"; string deleteQuery = "Delete Categories Where Num >= 20"; using (SqlConnection con = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionSt..

    Read more
  • 13.ADO.NET - DbProviderFactory

    Category ASP.NET on 2009. 9. 25. 12:09

    [ Web.config 데이터베이스 연결문자열 지정 ] FrmDbProviderFactory.aspx FrmDbProviderFactory.aspx.cs protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DisplayData(); } } private void DisplayData() { //[!] SQL Server, Oracle, Access DB에서 모두 똑같은 코드로 작성하고자한다면??? //[1] Configuration 정보 가져오기 : ProviderName에 따른 공급자 결정 DbProviderFactory factory = DbProviderFactories.GetFactory( Configurat..

    Read more
  • 12.ADO.NET - Parameters

    Category ASP.NET on 2009. 9. 25. 11:33

    입력한 범위에 대해서 값을 가져오는 예제입니다. Web.config에 [ 데이터베이스 연결문자열 지정 ] FrmParameters.aspx 번~ 번 사이의 카테고리 출력 FrmParameters.aspx.cs protected void btnSelect_Click(object sender, EventArgs e) { //[1] 변수 선언부 string first = txtFirst.Text; string second = txtSecond.Text; //[2] 커넥션 using (SqlConnection con = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { con.Open(..

    Read more
  • 11.ADO.NET - ExecuteScalar

    Category ASP.NET on 2009. 9. 25. 10:40

    예제를 위해서 Web.config에 데이터베이스 연결문자열을 입력합니다. [ Web.config ] FrmExecuteScalar.aspx 현재 카테고리 개수 : 등록된 상품 개수 : FrmExecuteScalar.aspx.cs protected void Page_Load(object sender, EventArgs e) { DisplayCategoryCount(); DisplayProductCount(); } private void DisplayProductCount() { SqlConnection con = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); con.Open(); ..

    Read more
  • 10.ADO.NET - ConfigurationManager

    Category ASP.NET on 2009. 9. 25. 09:56

    web.config 파일에 데이터베이스 연결 문자열을 지정하게되면 해당 프로젝트 전체에서 사용가능 합니다. web.config name="ConnectionString" connectionString="server=WINDOWS-XP\SQLSERVER;database=Test;uid=Test; pwd=1234;" providerName="System.Data.SqlClient"/> 안에 코드를 추가합니다. FrmConfigurationManager.aspx.cs protected void Page_Load(object sender, EventArgs e) { // Web.config 파일에 있는 섹션에 있는 값 읽어오기 string str = ConfigurationManager.ConnectionStr..

    Read more
  • 09.ADO.NET - ADO.NET ( 입력값 저장 )

    Category ASP.NET on 2009. 9. 25. 09:47

    입력한 값을 데이터베이스에 추가하기 FrmADONET.aspx FrmADONET.aspx.cs protected void Page_Load(object sender, EventArgs e) { //[1] 페이지 처음 로드시 모든 카테고리 리스트 출력 if (!Page.IsPostBack) { DisplayData(); } } // 출력 private void DisplayData() { SqlConnection con = new SqlConnection( "Data Source=WINDOWS-XP\\SQLSERVER;Initial Catalog=Test;User ID=Test;Password=1234;"); con.Open(); SqlCommand cmd = new SqlCommand("Select * ..

    Read more
  • 08.ADO.NET - 데이터베이스 연결 여러번 사용하기

    Category ASP.NET on 2009. 9. 24. 14:17

    데이터베이스 연결을 여러곳에서 사용하는 예제입니다. FrmSqlConnectionWithUsing.aspx FrmSqlConnectionWithUsing.aspx.cs public partial class FrmSqlConnectionWithUsing : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } private string connectionString; // 필드 : 데이터베이스연결문자열 저장 public FrmSqlConnectionWithUsing()// 생성자 : 연결문자열 초기화 { connectionString = "server=WINDOWS-XP\\SQLSERVER;database=Test;uid..

    Read more
  • 07.ADO.NET - SqlError

    Category ASP.NET on 2009. 9. 24. 14:04

    Error 결과를 출력하는 예제입니다. FrmSqlError.aspx Error 처리가 잘되는지 확인 하기 위해서 데이터베이스 로그인 비밀번호를 틀리게 입력합니다. FrmSqlError.aspx.cs protected void btnConnect_Click(object sender, EventArgs e) { // 커넥션 SqlConnection con = new SqlConnection(); con.ConnectionString = "server=WINDOWS-XP\\SQLSERVER;database=Test;uid=Test;pwd=123;"; // 커멘드 SqlCommand cmd = new SqlCommand("Select * From Categories", con); cmd.CommandType ..

    Read more
  • 06.ADO.NET - SqlDataReaderRead

    Category ASP.NET on 2009. 9. 24. 12:19

    값을 입력하여 결과값을 출력하는 예제입니다. Test DB에서 Categories 테이블을 수정합니다. Categories Table Update 1. 해당 테이블을 선택하고 마우스 오른쪽 클릭 - 디자인 2. 해당 테이블에 값을 입력합니다. 3. 쿼리문으로 값을 입력 4. 한 줄씩 블록을 지정하시고 F5 눌러서 실행해주세요 FrmSqlDataReaderRead.aspx 번 카테고리 출력 카테고리명 : (문자열) 부모카테고리 : (널가능 또는 정수형) 정렬순서 : (정수형) FrmSqlDataReaderRead.aspx.cs protected void btnSelect_Click(object sender, EventArgs e) { // 커넥션 SqlConnection con = new SqlConnec..

    Read more
  • 05.ADO.NET - SqlDataReader

    Category ASP.NET on 2009. 9. 24. 11:41

    데이터 베이스에 저장된 값을 출력하는 예제입니다. [ 이전에 저장한 값을 불러오기 ] FrmSqlDataReader.aspx FrmSqlDataReader.aspx.cs protected void Page_Load(object sender, EventArgs e) { // 폼이 처음로드할 때에만 Select하자... if (!Page.IsPostBack) { DisplayData(); } } private void DisplayData() { SqlConnection con = new SqlConnection( "server=WINDOWS-XP\\SQLSERVER;database=Test;uid=Test;pwd=1234;"); con.Open(); SqlCommand cmd = new SqlCommand..

    Read more
  • 04.ADO.NET - SqlCommand

    Category ASP.NET on 2009. 9. 24. 11:05

    코드를 통해서 데이터베이스에 값을 입력하는 예제입니다. Test 이름의 데이터 베이스에서 테이블을 설계합니다. [ 데이터베이스 만들기 ] 테이블 설계 1. Test 이름의 DB에서 테이블 추가 2. 테이블 만들기 Num은 번호로 자동 증가값을 설정합니다. CategoryName 필드명 지정, 테이블 이름 Categories FrmSqlCommand.aspx.cs 카테고리에 데이터 입력 FrmSqlCommand.aspx.cs protected void btnCommand_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "server=WINDOWS-XP\\SQLSERVER;dat..

    Read more
  • 03.ADO.NET - SqlException

    Category ASP.NET on 2009. 9. 24. 10:49

    FrmSqlException.aspx FrmSqlException.aspx.cs protected void btnConnect_Click(object sender, EventArgs e) { // 커넥션 스트링 자리를 SqlConnectionStringBuilder로 처리 SqlConnection con = new SqlConnection( (new SqlConnectionStringBuilder( "server=WINDOWS-XP\\SQLSERVER;database=Test;uid=Test;pwd=1234;")) .ConnectionString); // 잘못된 연결문자열 지정 후 에러 발생... try { con.Open(); lblError.Text = "연결완료"; } catch (SqlExcept..

    Read more
1 ··· 9 10 11 12 13