제 21 장 : ADO.NET 을 이용한 데이터 접근. ADO.NET - DataSet 사용하기.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

ADO.NET: Working in Disconnected Environment Sergey Baidachni MCT, MCSD, MCDBA.
Disconnected Data Applications: using Datasets, XML and Transactions.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
1 ADO.NET. 2.NET Framework Data Namespaces System.Data –Base set of classes and interfaces for ADO.NET System.Data.Common –Classes shared by the.NET Data.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS546.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Chapter 61 Managing Data Sources Introduction to ASP.NET By Kathleen Kalata.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
CHAPTER EIGHT Accessing Data Processing Databases.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Chapter 3 Introduction to ADO.NET 3.1 The ADO and ADO.NET ActiveX Data Object (ADO) is developed based on Object Linking and Embedding (OLE) and Component.
Viewing.NET Data Asad Usman Khan Syed Amier Haider Rehan Ahmad.
Moving from Microsoft ® ADO 2.X To ADO.NET Jackie Goldstein Renaissance Computer Systems Ltd. MSDN Regional Director, Israel Prerequisites.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
Module 4: Building DataSets. Overview Working in a Disconnected Environment Building DataSets and DataTables Binding and Saving a DataSet Defining Data.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
Mauricio Featherman, Ph.D. Washington St. University
Accessing Data with Microsoft Visual C# Applications.
Building Data-Centric Smart Client Applications Rajiv Sodhi Microsoft India.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
1 11/15/05CS360 Windows Programming ADO.NET Continued.
HNDIT Rapid Application Development
DataSets Demystified. Who I am Shawn Wildermuth Senior Consultant with Magenic Technologies ( C# MVP INETA.
ADO.NET in VB.NET 2005 ITE 370 4/26/2017.
C# .NET Software Development
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Module 5 Data Classes DataView – DataGridView Control 1.
DAT200 Microsoft® ADO.NET for ADO Classic Developers: Introducing ADO.NET Jackie Goldstein Renaissance Computer Systems
DataGridView. Displaying data in a tabular format is a task you are likely to perform frequently. The DataGridView control is designed to be a complete.
Introduction to ADO.Net Malek Kemmou CEO Arrabeta
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
Coding ADO.Net DataSet Objects ISYS 512. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set.
 2002 Prentice Hall. All rights reserved. 1 Chapter 19 – Database, SQL, and ADO.NET Outline 19.1 Introduction 19.2 Relational Database Model 19.3 Relational.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
.NET Data Access and Manipulation
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Introduction to ADO.NET
Copyright Scott-Jones Publishing, All rights reserved.
Introduction to Database Processing with ADO.NET
ADO.NET and Stored Procedures
ADO.NET Framework.
.NET Data Access and Manipulation
Distributed Database Systems
Active Data Objects Binding ASP.NET Controls to Data
DataSet и SqlDataAdapter
VB.NET Using Database.
Tonga Institute of Higher Education
מתחברים למסד נתונים היכרות עם ADO.Net.
Bài 5: ADO.NET 5.1. Khái niệm 5.2. Các lớp và không gian tên cơ bản của ADO.NET 5.3. Thao tác với dữ liệu kết nối – Connected 5.4. Thao tác với dữ liệu.
برنامه نویسی سیستم های شی گرا
Browser (Client Side) 瀏覽器 (客戶端)
Web Service.
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Active Data Objects Binding ASP.NET Controls to Data
Presentation transcript:

제 21 장 : ADO.NET 을 이용한 데이터 접근

ADO.NET - DataSet 사용하기

학습목표 DataSet 모델 DataSet 과 관련된 중요 객체 DataTable 의 중요 멤버 DataRow 의 중요 멤버 DataSet 테이블 및 필드 추가히기 DataSet 레코드 삽입하기 DataSet 레코드 변경 DataSet 데이터 검색 DataSet 제약 사항 추가

DataSet 객체 모델 DataSet 객체 모델 – 메모리 상의 데이터 베이스

DataSet 과 관련된 중요 객체 –DataTable –DataRow –DataRelation –DataColumn –DataView –DataSetView –DataRowView –…

ds.Tables["DSTitles"].Rows[i]["title_id"].ToString()); Tables : Collection DataTable 의 중요 멤버 –Rows, Columns, TableName –AcceptChanges(), RejectChanges() //Update, Delete 시 반드시 호출해야만 수행 –NewRow() –Constraints, PrimaryKey –ChildRelations –DefaultView DataTable

ds.Tables["DSTitles"].Rows[i]["title_id"].ToString()); Rows : Collection DataRow 의 중요 멤버 –Delete() –AcceptChages(), RejectChanges() –BeginEdit(), EndEdit() // AcceptChanges() 메소드 자동 호출된다. –GetChildRows() –RowState DataRow

DataTable orders = ds.Tables.Add("Orders"); orders.Columns.Add("ord_id",typeof(int)); orders.Columns.Add("amount",typeof(int)); orders.Columns.Add("employee_id",typeof(int)); orders.Columns.Add("product_id",typeof(int)); DataTable products = ds.Tables.Add("Products"); products.Columns.Add("product_id", typeof(int)); products.Columns.Add("product_name",typeof(string)); DataTable orders = ds.Tables.Add("Orders"); orders.Columns.Add("ord_id",typeof(int)); orders.Columns.Add("amount",typeof(int)); orders.Columns.Add("employee_id",typeof(int)); orders.Columns.Add("product_id",typeof(int)); DataTable products = ds.Tables.Add("Products"); products.Columns.Add("product_id", typeof(int)); products.Columns.Add("product_name",typeof(string)); DataSet 테이블 및 필드 추가하기

DataRow newrow = ds.Tables["DataSetTitles"].NewRow(); newrow["title_id"] = “XXX"; newrow["title"] = “ 타이틀 제목 "; ds.Tables["DataSetTitles"].Rows.Add(newrow); DataRow newrow = ds.Tables["DataSetTitles"].NewRow(); newrow["title_id"] = “XXX"; newrow["title"] = “ 타이틀 제목 "; ds.Tables["DataSetTitles"].Rows.Add(newrow); DataSet 에러코드 삽입하기 DataSet 내의 레코드 삽입

ds.Tables["DataSetTitles"].Rows[0].Delete(); // ds.Tables["DataSetTitles"].RejectChanges(); ds.Tables["DataSetTitles"].AcceptChanges(); ds.Tables["DataSetTitles"].Rows[0].Delete(); // ds.Tables["DataSetTitles"].RejectChanges(); ds.Tables["DataSetTitles"].AcceptChanges(); DataSet 사용하기 DataSet 내의 레코드 삭제

ds.Tables["DataSetTitles"].Rows[0].BeginEdit(); ds.Tables["DataSetTitles"].Rows[0]["title"] = " 타이틀 바꿈 "; ds.Tables["DataSetTitles"].Rows[0].EndEdit(); // ds.Tables["DataSetTitles"].AcceptChanges() ds.Tables["DataSetTitles"].Rows[0].BeginEdit(); ds.Tables["DataSetTitles"].Rows[0]["title"] = " 타이틀 바꿈 "; ds.Tables["DataSetTitles"].Rows[0].EndEdit(); // ds.Tables["DataSetTitles"].AcceptChanges() DataSet 사용하기 DataSet 내의 레코드 변경 호출할 필요 없다.

DataRelation relation = new DataRelation("T_TAuthor", ds.Tables["DataSetTitles"].Columns["title_id"], ds.Tables["DataSetTitleAuthor"].Columns["title_id"]); ds.Relations.Add(relation); DataRelation relation = new DataRelation("T_TAuthor", ds.Tables["DataSetTitles"].Columns["title_id"], ds.Tables["DataSetTitleAuthor"].Columns["title_id"]); ds.Relations.Add(relation); DataSet 사용하기 DataSet 내의 두 테이블 관계 맺기

DataRow[] childtrows = ds.Tables["DataSetTitles"].Rows[0].GetChildRows ("T_TAuthor") ci = 0; while(ci < childrows.Length) { Console.WriteLine(childrows[ci]["au_id"].ToString()); ci++; } DataRow[] childtrows = ds.Tables["DataSetTitles"].Rows[0].GetChildRows ("T_TAuthor") ci = 0; while(ci < childrows.Length) { Console.WriteLine(childrows[ci]["au_id"].ToString()); ci++; } DataSet 사용하기 DataSet 내의 관계를 이용한 데이터 검색

ds.Tables["DSTitles"].PrimaryKey = new DataColumn[] { ds.Tables["DSTitles"].Columns["title_id"]}; ds.Tables["DSTitles"].Columns["title_id"].AllowDBNull = false; ds.Tables["DSTitles"].Columns["title_id"].Unique = true; ds.Tables["DSTitles"].Columns["title_id"].DefaultValue = "BU0000“; ds.Tables["DSTitles"].PrimaryKey = new DataColumn[] { ds.Tables["DSTitles"].Columns["title_id"]}; ds.Tables["DSTitles"].Columns["title_id"].AllowDBNull = false; ds.Tables["DSTitles"].Columns["title_id"].Unique = true; ds.Tables["DSTitles"].Columns["title_id"].DefaultValue = "BU0000“; DataSet 사용하기 DataSet 내의 테이블에 제약 설정 하기

데모 1. 프로젝트 생성 및 폼 디자인

데모 2. 코드 삽입 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace AdoDataset { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.DataGrid dataGrid1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; … static void Main() { Application.Run(new Form1()); }

데모 2. 코드 삽입 DataSet ds = new DataSet(); DataTable roans; DataTable books; private void button4_Click(object sender, System.EventArgs e) { roans = ds.Tables.Add("Roans"); roans.Columns.Add("amount", typeof(int)); roans.Columns.Add("sabun", typeof(int)); roans.Columns.Add("books_id", typeof(int)); books = ds.Tables.Add("Books"); books.Columns.Add("books_id", typeof(int)); books.Columns.Add("books_name", typeof(string)); books.Columns["books_id"].AutoIncrement = true; books.PrimaryKey = new DataColumn[] { books.Columns["books_id"]}; books.Columns["books_id"].Unique = true; books.Columns["books_id"].AllowDBNull = true; dataGrid1.DataSource = books; } private void button1_Click(object sender, System.EventArgs e) { DataRow newrow = books.NewRow(); newrow["books_name"] = textBox1.Text; books.Rows.Add(newrow); }

데모 2. 코드 삽입 private void button2_Click(object sender, System.EventArgs e) { int idx = dataGrid1.CurrentRowIndex; books.Rows[idx].BeginEdit(); books.Rows[idx]["books_name"] = textBox1.Text; books.Rows[idx].EndEdit(); } private void button3_Click(object sender, System.EventArgs e) { int idx = dataGrid1.CurrentRowIndex; books.Rows[idx].Delete(); books.AcceptChanges(); //books.Row[current_product_id].RejectChanges(); dataGrid1.CurrentRowIndex = 0; }

ADO.NET SQL Server.NET DataProvider - SqlDataAdapter 데이터 추출

학습 목표 SqlDataAdapter 와 DataSet SqlDataAdapter 의 주요 멤버 SqlDataAdapter 를 이용한 데이터 추출 데모 DataView 사용

ord_idprod_idamount 1BU BU Data Source DataSet in Memory Table Mapping - Orders to Orders SqlDataAdapter.SelectCommand SqlDataAdapter.UpdateCommand.InsertCommand.DeleteCommand ord_idprod_idamount 1BU BU SqlDataAdapter 와 DataSet

SqlDataAdapter 의 주요 멤버 –SelectCommand, InsertCommand, UpdateCommand, DeleteCommand –Fill(), // SelectCommand() 를 이용해서 실제 데이터 저장소로부터 데이터를 스키마 // 를 생성한 후 이를 가져오는 역할을 한다. –Update() –TableMappings SqlDataAdapter 의 주요 이벤트 –RowUpdated, RowUpdating

sqlConnection1.ConnectionString SqlCommand comd = new SqlCommand * From Titles",sqlConnection1); SqlDataAdatper dsc = new SqlDataAdaptor(); dsc.SelectCommand = comd; DataSet ds = new DataSet(); dsc.Fill(ds,"DSTitles"); int i = 0; while(i < ds.Tables["DSTitles"].Rows.Count) { Console.WriteLine( ds.Tables["DSTitles"].Rows[i]["title_id"].ToString()); i++; } sqlConnection1.ConnectionString SqlCommand comd = new SqlCommand * From Titles",sqlConnection1); SqlDataAdatper dsc = new SqlDataAdaptor(); dsc.SelectCommand = comd; DataSet ds = new DataSet(); dsc.Fill(ds,"DSTitles"); int i = 0; while(i < ds.Tables["DSTitles"].Rows.Count) { Console.WriteLine( ds.Tables["DSTitles"].Rows[i]["title_id"].ToString()); i++; } SqlDataAdapter 를 이용한 데이터 추출 SqlDataAdaptor 의 사용

DataView dv; dv = new DataView (ds.Tables["Authors“]); dv.RowFilter = "state = 'CA'" ; DataView dv; dv = new DataView (ds.Tables["Authors“]); dv.RowFilter = "state = 'CA'" ; DataView dv; dv = ds.Tables["Authors“].DefaultView; DataView dv; dv = ds.Tables["Authors“].DefaultView; DataView 사용 DataTable 의 데이터 중 원하는 데이터만 걸러내기위해서 사용 DataTable 의 DefaultView 프로퍼티 –DataTable 의 전체 데이터를 반환하는 DataView 객체 DataView.RowFilter 프로퍼티 사용하기 DataTable.DefaultView 프로퍼티 사용하기

1. 프로젝트 생성 및 폼 디자인 TreeView

2-1. SqlCommand1

2-2. SqlCommand1

2-2. SqlCommand2 CommandText Connection

3. 어댑터 프로그램 작성 DataSet Sehyun = new DataSet(); private void button1_Click(object sender, System.EventArgs e) { SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = sqlCommand1; adapter.Fill(Sehyun,"iOrders"); adapter.SelectCommand = sqlCommand2; adapter.Fill(Sehyun,"iProducts"); Sehyun.Relations.Add( "ProductsOrders", Sehyun.Tables["iProducts"].Columns["product_id"], Sehyun.Tables["iOrders"].Columns["product_id"] ); TreeNode root = new TreeNode(" 제품들 "); treeView1.Nodes.Add(root); for(int i=0;i < Sehyun.Tables["iProducts"].Rows.Count; ++i) { TreeNode productNode = root.Nodes.Add( (string) Sehyun.Tables["iProducts"].Rows[i]["product_name"]); DataRow[] childRows; childRows = Sehyun.Tables["iProducts"].Rows[i].GetChildRows("ProductsOrders"); for(int k=0; k<childRows.Length; k++) productNode.Nodes.Add(childRows[k]["amount"].ToString()); }

4. 데이터 뷰 프로그램 private void button2_Click(object sender, System.EventArgs e) { DataView dv; dv = new DataView(Sehyun.Tables["iOrders"]); dv.RowFilter = "product_id = 3"; foreach(DataRowView drv in dv) { MessageBox.Show(drv["amount"].ToString()); }

ADO.NET SQL Server.NET DataProvider - SqlDataAdapter 데이터 갱신

학습 목표 SqlDataAdapter 와 DataSet SqlDataAdapter 의 주요 멤버 SqlDataAdapter 를 이용한 데이터 갱신 데모

ord_idprod_idamount 1BU BU Data Source DataSet in Memory Table Mapping - Orders to Orders SqlDataAdapter.SelectCommand SqlDataAdapter.UpdateCommand.InsertCommand.DeleteCommand ord_idprod_idamount 1BU BU SqlDataAdapter 와 DataSet

SqlDataAdapter 의 주요 멤버 –SelectCommand, InsertCommand, UpdateCommand, DeleteCommand –Fill(), Update() –TableMappings SqlDataAdapter 의 주요 이벤트 –RowUpdated, RowUpdating

New300BU10112 Modified300BU amount UnchangedBU10112 DeletedBU10321 DataRow.RowStateprod_idord_id SqlDataAdapter.Update() 호출 시 DataRow.Deleted 레코드 - SqlDataAdapter.DeleteCommand 에 의해 삭제 DataRow.Modified 레코드 - SqlDataAdapter.UpdateCommand 에 의해 갱신 DataRow.New 레코드 - SqlDataAdapter.InsertCommand 에 의해 추가 OrdersDS.GetChanges(System.Data.DataRowState.Deleted) OrdersDS.GetChanges(System.Data.DataRowState.Modified)... SqlDataAdapter 를 이용한 데이터 갱신 (1) 메모리 상에서 Flag 가 덧붙는다. Delete Flag 가 붙은 것을 가져와서 테이블을 만들어라

ord_idprod_idamount 1BU BU ord_idprod_idamount 1BU BU Data Source – Orders SqlDataAdapter.UpdateCommand.InsertCommand.DeleteCommand.Update DataSet in Memory – Orders SqlParameter.SourceColumn 으로 지정 SqlDataAdapter 를 이용한 데이터 갱신 (2)

데모 데이터 갱신 DataSet.GetChanges() 이벤트 데이터 추가

1. 프로젝트 생성 및 폼 디자인 TreeView 데이터 갱신

2-1. SqlCommand1 데이터 갱신

2-2. SqlCommand1 데이터 갱신

2-2. SqlCommand2 CommandText Connection 데이터 갱신

3. 어댑터 프로그램 작성 DataSet Sehyun = new DataSet(); private void button1_Click(object sender, System.EventArgs e) { SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = sqlCommand1; adapter.Fill(Sehyun,"iOrders"); adapter.SelectCommand = sqlCommand2; adapter.Fill(Sehyun,"iProducts"); Sehyun.Relations.Add( "ProductsOrders", Sehyun.Tables["iProducts"].Columns["product_id"], Sehyun.Tables["iOrders"].Columns["product_id"] ); TreeNode root = new TreeNode(" 제품들 "); treeView1.Nodes.Add(root); for(int i=0;i < Sehyun.Tables["iProducts"].Rows.Count; ++i) { TreeNode productNode = root.Nodes.Add( (string) Sehyun.Tables["iProducts"].Rows[i]["product_name"]); DataRow[] childRows; childRows = Sehyun.Tables["iProducts"].Rows[i].GetChildRows("ProductsOrders"); for(int k=0; k<childRows.Length; k++) productNode.Nodes.Add(childRows[k]["amount"].ToString()); } 데이터 갱신

4. AfterSelect 속성 추가 private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { textBox1.Text = e.Node.Text; } 데이터 갱신

5. Update 버튼 이벤트 핸들러 추가 bool NodeTest(TreeNode node, int depth) { if(node == null) return false; else if(depth == 0) return true; return NodeTest(node.Parent, depth-1); } private void button2_Click(object sender, System.EventArgs e) { if( NodeTest(treeView1.SelectedNode,2) ) treeView1.SelectedNode.Text = textBox1.Text; } 데이터 갱신

6-1. sqlCommand3 추가 – Update 용 추가 데이터 갱신

6-2. sqlCommand3 추가 – Update 용 CommandText 데이터 갱신

6-3. sqlCommand3 추가 – Update 용 데이터 갱신

7. Save 버튼 이벤트 핸들러 추가 private void button3_Click(object sender, System.EventArgs e) { DataTable products = Sehyun.Tables["iProducts"]; TreeNodeCollection productNodes = treeView1.Nodes[0].Nodes; for(int i=0; i<productNodes.Count; ++i) { DataRow[] childRows = products.Rows[i].GetChildRows("ProductsOrders"); int node_num = 0; foreach(DataRow row in childRows) { row.BeginEdit(); if((int) row["amount"] == Int32.Parse(productNodes[i].Nodes[node_num].Text)) { row.RejectChanges(); node_num++; continue; } row["amount"] = Int32.Parse(productNodes[i].Nodes[node_num].Text); row.EndEdit(); node_num++; } SqlDataAdapter adapter = new SqlDataAdapter(); adapter.UpdateCommand = sqlCommand3; adapter.Update(Sehyun, “ iOrders"); } 데이터 갱신

1. button3_Click() 함수에 다음의 코드 추가 private void button3_Click(object sender, System.EventArgs e) { … // DataSet.GetChagnes Demo DataSet temp = Sehyun.GetChanges(DataRowState.Modified); string result = ""; for(int j=0;j<temp.Tables[0].Rows.Count;++j) result = result + "/" + temp.Tables[0].Rows[j]["amount"].ToString(); MessageBox.Show(result); /////////////////////////////////////////////////////////////////// SqlDataAdapter adapter = new SqlDataAdapter(); adapter.UpdateCommand = sqlCommand3; adapter.Update(Sehyun, “ iOrders"); } DataSet.GetChanges()

1. button3_Click() 함수에 다음의 코드 추가 private void button3_Click(object sender, System.EventArgs e) { SqlDataAdapter adapter = new SqlDataAdapter(); adapter.UpdateCommand = sqlCommand3; adapter.RowUpdated += new SqlRowUpdatedEventHandler (OnRowUpdated); adapter.RowUpdating += new SqlRowUpdatingEventHandler (OnRowUpdating); adapter.Update(Sehyun, “ iOrders"); } void OnRowUpdated(object s, SqlRowUpdatedEventArgs e) { MessageBox.Show(e.Row["amount"].ToString() + e.Row.RowState.ToString() +" Updated"); } void OnRowUpdating(object s, SqlRowUpdatingEventArgs e) { MessageBox.Show(e.Row["amount"].ToString() + e.Row.RowState.ToString() + " Updating"); } 이벤트 핸들러 추가

1. sqlCommand4 추가 데이터 추가

2. Connection, CommandText 수정 데이터 추가

3. Parameters 확인 데이터 추가

4. Button4_Click() 이벤트 작성 데이터 추가 private void button4_Click(object sender, System.EventArgs e) { DataRow newrow = Sehyun.Tables["iProducts"].NewRow(); newrow["product_id"] = 9999; newrow["product_name"] = textBox2.Text; Sehyun.Tables["iProducts"].Rows.Add(newrow); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.InsertCommand = sqlCommand4; adapter.Update(Sehyun,"iProducts"); }

Typed DataSet 생성 및 사용

학습목표 Typed DataSet 이란 ? XML Schema 와 Typed DataSet Typed DataSet 생성

Typed DataSet 이란 ? 데이터 베이스의 각 요소 ( 테이블, 필드, 제약 … ) 를 멤버화 한 데이터 객체 DataSet 을 상속 XML Schema 를 기반으로 Visual Studio.NET 에서 자동 생성 장점 – 컴파일 시 타입 에러 발견 – 컴포넌트화가 가능 하다. – 이름 완성 기능 사용 등으로 사용이 간편 (. 을 찍으면 속성이 나오는 것을 의미 )

ord_id (Int)prod_id (Char)amount (int) 1BU BU DataSet 내의 Orders 테이블 class OrdersDataSet : DataSet { class OrdersTable : DataTable { class OrdersRow : DataRow { int ord_id; string pord_id int amount; } OrdersRow[] Item; } OrdersTable Orders; } class OrdersDataSet : DataSet { class OrdersTable : DataTable { class OrdersRow : DataRow { int ord_id; string pord_id int amount; } OrdersRow[] Item; } OrdersTable Orders; } XML Schema XML Schema 와 Typed DataSet

Typed DataSet 생성 Typed DataSet 생성 순서  XML Schema 생성 DataSet 생성 위저드 Server Explorer 이용 XML Schema 편집  Typed DataSet 생성

데모