VS_chapter10

Similar documents
(Microsoft PowerPoint - ADONET [\310\243\310\257 \270\360\265\345])

한국 컴퓨터그래픽스(디지털컨텐츠)의 현황과 미래 위기인가? 기회인가?

ALTIBASE 사용자가이드 Templete

Microsoft PowerPoint - CSharp-12-데이터베이스

Microsoft PowerPoint - 07-C#-13-ADO.ppt [호환 모드]

10.ppt

untitled

ALTIBASE 사용자가이드 Templete

untitled

<성진수의 C# 활용 2>

untitled

untitled

초보자를 위한 ADO 21일 완성

3ÆÄÆ®-11

3ÆÄÆ®-14

untitled


chapter4

untitled

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

초보자를 위한 ASP.NET 21일 완성

03. ADO 닷넷 ADO 닷넷이란? ADO(ActiveX Data Objects) 의닷넷버전 비연결방식 (Discected Mdel) 제공 데이터베이스와연결후필요한데이터를가져온후에, 접속을바로끊고나서도데이터를계속해서처리할수있는방법이필요 자원을계속많이확보가능 자료의처리

Visual Basic 반복문

NoSQL

FileMaker 15 ODBC 및 JDBC 설명서

FileMaker ODBC 및 JDBC 가이드

FileMaker ODBC and JDBC Guide

02 C h a p t e r Java

초보자를 위한 C# 21일 완성

(Humphery Kim) RAD Studio : h=p://tech.devgear.co.kr/ : h=p://blog.hjf.pe.kr/ Facebook : h=p://d.com/hjfactory :

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

Microsoft PowerPoint - 04-UDP Programming.ppt

학습목표 함수프로시저, 서브프로시저의의미를안다. 매개변수전달방식을학습한다. 함수를이용한프로그래밍한다. 2

DocsPin_Korean.pages

학습목표 배열에대해서안다. 언어통합질의 (LINQ) 에대해서안다. 2

UNIST_교원 홈페이지 관리자_Manual_V1.0

C++Builder ADO Programming (5) - ADO Transaction, Errors

thesis

歯JavaExceptionHandling.PDF

13 주차 - MDI, Exception, WebBrowser, RichTextBox, AlarmProgram 대림대학 년도 1 학기홍명덕

rmi_박준용_final.PDF

1

Interstage5 SOAP서비스 설정 가이드

PowerPoint 프레젠테이션

歯처리.PDF

01_피부과Part-01

DBMS & SQL Server Installation Database Laboratory

학습목표 텍스트파일을다룰수있다. 스트림읽기, 쓰기를안다. 2

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

Session3. 한국마이크로소프트(전사적 데이터 통합 컨퍼런스).ppt

Microsoft PowerPoint - 10Àå.ppt

Microsoft SQL Server 2005 포켓 컨설턴트 관리자용

Ç¥Áö

FileMaker ODBC and JDBC Guide

PowerPoint 프레젠테이션

13주-14주proc.PDF

초보자를 위한 한글 Visual Basic .NET 21일 완성

Orcad Capture 9.x

01....b

¾Ë·¹¸£±âÁöħ¼�1-ÃÖÁ¾

2007백서-001-특집

00목차

(291)본문7

歯엑셀모델링

목차 BUG offline replicator 에서유효하지않은로그를읽을경우비정상종료할수있다... 3 BUG 각 partition 이서로다른 tablespace 를가지고, column type 이 CLOB 이며, 해당 table 을 truncate

Copyright 2012, Oracle and/or its affiliates. All rights reserved.,.,,,,,,,,,,,,.,...,. U.S. GOVERNMENT END USERS. Oracle programs, including any oper

C# 입문 : 이론과 실습

USER GUIDE

Microsoft PowerPoint - web-part03-ch19-node.js기본.pptx

초보자를 위한 크리스탈 리포트 9 - 대화형 리포트의 작성과 디자인

작성자 : 한동훈 제목 : 효율적인웹응용프로그램구축 들어가기두번째섹션에서는먼저데이터액세스계층 (DAL: Data Access Layer) 작성에대한이야기를했습니다. 따라서데이터액세스계층에대해서먼저살펴본다음에 ASP.NET을기준으로 'Everything in one pa

페이지 2 / 9 목차 개요웹취약점분류점검결과해결방안 주의사항 : 빛스캔 ( 주 ) 의취약성검사가대상웹사이트의취약점을 100% 진단하지못할가능성이있으며, 원격에서탐지 하는점검의특성상오탐지 (False Positive) 할가능성이있으므로충분한검토과정

MasoJava4_Dongbin.PDF

Microsoft Word - MS-SQL injections 공격 대처하기.doc

90

MySQL-Ch05

비긴쿡-자바 00앞부속

Java 프로그래머를 위한 C# 비교 활용

자바-11장N'1-502

신림프로그래머_클린코드.key

API - Notification 메크로를통하여어느특정상황이되었을때 SolidWorks 및보낸경로를통하여알림메시지를보낼수있습니다. 이번기술자료에서는메크로에서이벤트처리기를통하여진행할예정이며, 메크로에서작업을수행하는데유용할것입니다. 알림이벤트핸들러는응용프로그램구현하는데있어

8 장데이터베이스 8.1 기본개념 - 데이터베이스 : 데이터를조직적으로구조화한집합 (cf. 엑셀파일 ) - 테이블 : 데이터의기록형식 (cf. 엑셀시트의첫줄 ) - 필드 : 같은종류의데이터 (cf. 엑셀시트의각칸 ) - 레코드 : 데이터내용 (cf. 엑셀시트의한줄 )

USB USB DV25 DV25 REC SRN-475S REC SRN-475S LAN POWER LAN POWER Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl C

ORANGE FOR ORACLE V4.0 INSTALLATION GUIDE (Online Upgrade) ORANGE CONFIGURATION ADMIN O

EMBARCADERO TECHNOLOGIES (Humphery Kim) RAD Studio : h=p://tech.devgear.co.kr/ : h=p://blog.hjf.pe.kr/ Facebook : h=p://d.com/hjfactory :

JDBC 소개및설치 Database Laboratory

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

Chap7.PDF

第 1 節 組 織 11 第 1 章 檢 察 의 組 織 人 事 制 度 등 第 1 項 大 檢 察 廳 第 1 節 組 대검찰청은 대법원에 대응하여 수도인 서울에 위치 한다(검찰청법 제2조,제3조,대검찰청의 위치와 각급 검찰청의명칭및위치에관한규정 제2조). 대검찰청에 검찰총장,대

JMF2_심빈구.PDF

Delphi 2005 Reviewer's Guide

SQL Developer Connect to TimesTen 유니원아이앤씨 DB 기술지원팀 2010 년 07 월 28 일 문서정보 프로젝트명 SQL Developer Connect to TimesTen 서브시스템명 버전 1.0 문서명 작성일 작성자

PWR PWR HDD HDD USB USB Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl Cable PC PC DDNS (

PowerPoint 프레젠테이션

Dialog Box 실행파일을 Web에 포함시키는 방법

歯 Final.PDF

MS-SQL SERVER 대비 기능

3 S Q L A n t i p a t t e r n s Trees/intro/parent.sql CREATE TABLE Comments ( comment_id SERIAL PRIMARY KEY, parent_id BIGINT UNSIGNED, comment TEXT

2파트-07

Transcription:

Part. Chapter 10 ActiveX Data Objects.NET(ADO.NET).NET, ADO.NET..NET ADO(ActiveX Data Objects). ADO. ADO,. ADO,.NET ADO.NET... ADO.NET ADO Connection DataReader Command DataAdapter DataSet DataView DataSet 330

.NET (FCL) System.Data ( )..NET ADO. ADO,. ADO.NET., ADO ADO.NET. ADO ADO.NET. 10 Chapter...,,. ADO.NET. System.Data.SqlClient : SQL Server 7.0 SQL Server 2000. System.Data.OleDb : SQL Server (OLE DB). OLE DB, Microsoft Access, Excel, dbase. System.Data.Odbc : ODBC, 331

ODBC ODBC (DSN). ODBC. System.Data.OracleClient :. SqlClient OleDb.,,,. (System.Data.SqlClient System.Data.OleDb)., System.Data.SqlClient Connection System.Data.SqlClient.SqlConnection, OleDb System.Data.OleDb.OleDbConnection.. (SQL Server OleDb ). ADO 10.1 ADO ADO.NET. 332

, ADO.NET ADO.,.,. Connection,, Open. Command ADO. (Select), (Insert), (Update), (Delete) SQL Command. ADO.NET Command Parameters,. DataReader. ADO ForwardOnly., DataReader. 10 Chapter DataAdapter ADO.NET, ADO. DataAdapter, DataSet. DataAdapter. DataAdapter InsertCommand, UpdateCommand, SelectCommand, DeleteCommand. DataAdapter. DataSet ADO. DataSet,. DataSet, extensible markeup language(xml), XML. DataSet DataAdapter, DataAdapter Connection Command, DataSet. 333

. ADO.NET... (,,, ),. ADO. ADO.NET DataAdapter DataSet. (,, ).,,... DataSet. (rule), (constraint), (relationship). XML ADO.NET. XML. XML ADO.NET. ADO. NET XML. ADO.NET XML 334

,. XML.NET,. Visual Studio.NET FCL., [ 10.2] ADO.NET DataReader, DataAdapter, DataSet 10 Chapter 335

[ 10.2]. Visual Basic 6 ASP.,..NET.., ( ).. DataSet DataAdapter. DataReader 11.,. ADO.NET Connection. SQL Server SqlConnection (System.Data.SqlClient ) Connection, OLE DB OleDbConnection (System.Data.OleDb ) Connection.,,, (connection string)., SQL Server.. 336

OleDbConnection Microsoft Access.NET SDK (MSDE) SQL Server ID SQL Server ' System.Data.OleDb.OleDbConnection ' Dim stroledb As String = _ "Provider=Microsoft.Jet.OLEDB.4.0; " _ & "Data Source=..\Northwind.mdb" Dim cnoledb As New OleDbConnection() cnoledb.connectionstring = stroledb cnoledb.open() 10 Chapter ' System.Data.SqlClient.SqlConnection ' MSDE SDK Dim strmsde As String = _ "Server=(local)\NetSDK;DataBase=Northwind; " _ & "Integrated Security=SSPI" Dim cnmsde As New SqlConnection() cnmsde.connectionstring = strmsde cnmsde.open() ' System.Data.SqlClient.SqlConnection ' SQL Server Dim strsql As String = _ "Server=localhost;DataBase=Northwind;" & _ "Integrated Security=SSPI" Dim cnsql As New SqlConnection() cnsql.connectionstring = strsql cnsql.open() ' ID ' System.Data.SqlClient.SqlConnection ' SQL Server Dim strsql1 As String = _ 337

"Server=localhost;DataBase=Northwind;" & _ "uid=sa;pwd=password" Dim cnsql1 As New SqlConnection() cnsql1.connectionstring = strsql1 cnsql1.open() // System.Data.OleDb.OleDbConnection // string stroledb; stroledb = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\Northwind.mdb" OleDbConnection cnoledb = new OleDbConnection(); cnoledb.connectionstring = stroledb; cnoledb.open(); // System.Data.SqlClient.SqlConnection // MSDE SDK string strmsde; strmsde = @"Server=(local)\NetSDK;DataBase=Northwind;Integrated Security=SSPI" SqlConnection cnmsde = new SqlConnection(); cnmsde.connectionstring = strmsde; cnmsde.open(); // System.Data.SqlClient.SqlConnection // SQL Server string strsql; strsql = @"Server=localhost;DataBase=Northwind;Integrated Security=SSPI" SqlConnection cnsql = new SqlConnection(); cnsql.connectionstring = strsql; cnsql.open(); // ID // System.Data.SqlClient.SqlConnection // SQL Server string strsql1; strsql1 = 338

@"Server=localhost;DataBase=Northwind;uid=sa;pwd="; SqlConnection cnsql1 = new SqlConnection(); cnsql1.connectionstring = strsql1; cnsql1.open();, OleDbConnection SqlConnection., SQL Server ( localhost),, ID. OleDbConnection, OLE DB, OLE DB. OLE DB. Access. Oracle SQL Server 6.5, SQL Server 7.0 SQL Server 2000. 10 Chapter [ 10.1] SqlConnection OleDbConnection. 339

SqlConnection OleDbConnection ( ) (overload), Connection., Visual Basic.NET (, ). Dim cn as New SqlConnection("Server=localhost;DataBase=Northwind;" _ & "uid=sa;pwd=password"),. 340

Command SQL, SQL SQL (stored procedure). SqlCommand Command SQL Server, OleDbComand Command OLE DB. Command. Connection CreateCommand SqlCommand OleDbCommand (Command ) Connection Command SQL Command. [ 10.2] SqlCommand OleDbCommand Command. 10 Chapter 341

Command SQL Command Text, [ 10.3] SQL. Command,. ExecuteReader, DataReader.. DataReader. SqlDataReader OleDbDataReader.,. [ 10.1]., Command, DataReader. 342

Dim cn As New SqlConnection( _ "Server=(local)\NetSDK;DataBase=pubs;" _ & "Integrated Security=SSPI") ' SqlDataReader. Dim dr As SqlDataReader ' SqlCommand Dim cmd As New SqlCommand ' CommandText SQL Select, ' Connection SqlConnection ( ) cn. With cmd.commandtext = "Select au_lname, au_fname from Authors".Connection = cn End With 10 Chapter ' Connection. cn.open() ' Command ExecuteReader. dr = cmd.executereader(commandbehavior.closeconnection) Dim strname As String ' DataReader Read. While dr.read ' ListBox1. strname = dr("au_lname") & ", " & dr("au_fname") ListBox1.Items.Add(strName) End While ' Connection. cn.close() SqlConnection cn = new SqlConnection (@"Server=(local)\NetSDK;DataBase=pubs;Integrated 343

Security=SSPI"); // SqlDataReader. SqlDataReader dr; // SqlCommand SqlCommand cmd = new SqlCommand(); // CommandText SQL Select, // Connection SqlConnection ( ) cn. cmd.commandtext = "Select au_lname, au_fname from Authors"; cmd.connection = cn; // Connection. cn.open(); // Command ExecuteReader. dr = cmd.executereader(commandbehavior.closeconnection); string strname; // DataReader Read. while (dr.read()) { // listbox1. strname = dr.getstring(0) + ", " + dr.getstring(1); listbox1.items.add(strname); } // Connection. cn.close(); ExecuteReader, DataReader Read.,. While. Read False, While. DataReader 344

.. Visual Basic.NET. Do Until dr.read = False '. Loop [ 10.1] Visual Basic.NET C#, DataReader Read. Visual Basic.NET, C# GetString., 0, 1.,. [ 10.4] SqlDataReader. 10 Chapter 345

SQL Server OLE DB.. Visual Studio.NET DataReader. (DataReader ). C#, GetString. Visual Basic.NET string., System.Convert.. Insert, Update, Delete SQL ExecuteNonQuery. [ 10.2]. Sub DoNonQuery() Dim cn As New SqlConnection( _ "Server=(local)\NetSDK;DataBase=pubs;" _ & "Integrated Security=SSPI") Dim cmd As New SqlCommand With cmd.commandtext = "Delete from Authors where au_lname = 'Smith ".Connection = cn.commandtype = CommandType.Text End With Try cn.open() cmd.executenonquery() Catch ex As Exception MessageBox.Show(ex.Message) Finally 346

If cn.state = ConnectionState.Open Then cn.close() End If End Try End Sub private void DoNonQuery() { SqlConnection cn = new SqlConnection (@"Server=(local)\NetSDK;DataBase=pubs;Integrated Security=SSPI"); SqlCommand cmd = new SqlCommand(); cmd.commandtext = "Delete from Authors where au_lname = 'Smith " cmd.connection = cn; cmd.commandtype = CommandType.Text ; 10 Chapter } try { cn.open(); cmd.executenonquery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (cn.state == ConnectionState.Open) { cn.close(); } } [ 10.2] [ 10.1]. Connection Command, SQL., SQL. Insert, Update, Delete SQL,, 347

. ExecuteNonQuery. ExecuteReader. Connection State, connection close. Try ~ Catch, connection., connection close Finally close. Connection, Command, DataReader.., C# Visual Basic.NET. DataAccess_vb(Visual Basic.NET) DataAccess_cs(C#). DataAccess. Form1 ([ 10.3] ). 1. TabControl.. Dock : Fill TabPages: TabPage. TabPage. Text ( TabPage ). TabPage1 Text: Readers and Adapters TabPage2 Text: DataGrid Binding TabPage3 Text: Simple Data Entry TabPage. 2. Form1 TabPage1 Button.. 348

Button1: Text: Using a DataReader Name: UseDataReader Button2: Text: Using a DataSet Name: UseDataSet Button3: Text: Show Checked Items Name: ShowCheckedItems Button4: Text: DataBind with DataSet Name: DataBindWithDataSet 3. ListBox TabPage1. 4. CheckedListBox TabPage1. 5. ComboBox TabPage1. 10 Chapter 6. 3 Label TabPage1. [ 10.3]. (TabPage2, TabPage3).,,. [ 10.3] [ 10.1].,. 349

,. TabPage1, UseDataReader_Click. [ 10.3] ( )., Form1 Imports using.. Visual Basic.NET,. Imports System.Data.SqlClient Imports System.Text C#,. using System.Data.SqlClient; using System.Text; Private Sub UseDataReader_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles UseDataReader.Click ListBox1.Items.Clear() Dim cn As New SqlConnection( _ "Server=(local)\NetSDK;DataBase=pubs;" _ & "Integrated Security=SSPI") ' SqlDataReader. Dim dr As SqlDataReader ' SqlCommand. Dim cmd As New SqlCommand() ' CommandText SQL Select, ' Connection SqlConnection. With cmd.commandtext = "Select au_lname, au_fname from Authors".Connection = cn End With 350

' Connection open. cn.open() ' Command ExecuteReader. dr = cmd.executereader(commandbehavior.closeconnection) Dim strname As String ' DataReader Read ListBox1. While dr.read strname = dr("au_lname") & ", " & dr("au_fname") ListBox1.Items.Add(strName) End While End Sub private void UseDataReader_Click(object sender, System.EventArgs e) { 10 Chapter listbox1.items.clear(); SqlConnection cn = newsqlconnection(@"server=(local)\netsdk;database=pubs; Integrated Security=SSPI"); // SqlDataReader. SqlDataReader dr; // SqlCommand. SqlCommand cmd = new SqlCommand(); // CommandText SQL Select, // Connection SqlConnection. cmd.commandtext = "Select au_lname, au_fname from Authors"; cmd.connection = cn; // Connection open. cn.open(); // Command ExecuteReader. 351

dr = cmd.executereader(commandbehavior.closeconnection); string strname; // DataReader Read ListBox1. while (dr.read()) { strname = dr.getstring(0) + ", " + dr.getstring(1); listbox1.items.add(strname); } } ListBox1 SelectedIndexChanged. Button Click, ListBox, ListBox1, SelectedIndexChanged. [ 10.4] ( ). Private Sub ListBox1_SelectedIndexChanged _ (ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles ListBox1.SelectedIndexChanged ' ListBox1 Label1. Label1.Text = "ListBox1_SelectedIndexChanged" ' ListBox1 Label2. Label2.Text = ListBox1.Items(ListBox1.SelectedIndex) ' ListBox1 Label3. Label3.Text = ListBox1.SelectedIndex End Sub private void listbox1_selectedindexchanged(object sender, 352

System.EventArgs e) { // listbox1 Label1. label1.text = "ListBox1_SelectedIndexChanged"; // listbox1 Label2. label2.text = listbox1.text; } // listbox1 Label3. label3.text =listbox1.selectedindex.tostring(); [ 10.4] ListBox, ListBox.. 10 Chapter,. F5. Form1,. ListBox. ListBox Label. [ 10.4]. 353

DataReader.,,. DataReader, DataSet. DataSet. [ 10.2] DataSet. DataSet. DataTable. DataSet DataAdapter., DataSet DataAdapter. DataAdapter, Fill Update. Command SQL (Select ) Fill DataSet DataTable. DataAdapter Command,. Command SQL. SQL Server SqlDataAdapter, OleDb OleDbDataAdapter.. SqlDataAdapter, Command, DataSet Authors. cn Connection. ' SqlDataAdapter. Dim da As SqlDataAdapter = New SqlDataAdapter() ' Connection Command. Dim cmd As New SqlCommand("Select * from Authors", cn) 354

' SelectCommand Command. da.selectcommand = cmd ' SqlDataAdapter DataSet. Dim ds As DataSet = New DataSet() ' Command DataSet Fill method. da.fill(ds, "Authors") // SqlDataAdapter. SqlDataAdapter da = new SqlDataAdapter(); // Connection Command. SqlCommand cmd = new SqlCommand("Select * from Authors", cn); // SelectCommand Command. da.selectcommand = cmd; 10 Chapter // SqlDataAdapter DataSet. DataSet ds = new DataSet(); // Command DataSet Fill method. da.fill(ds, "Authors"); DataAdapter Fill., Command SQL (Select ) (row) DataSet. connection open open open. close. 11, DataAdapter Update DataSet Insert, Update, Delete. DataAdapter, InsertCommand, UpdateCommand, DeleteCommand. SQL,., (batch). 355

DataAdapter, DataAdapter SQL. Visual Basic.NET, SqlDataAdapter SQL (Select) Connection. Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from Customers", cn ) DataSet DataAdapter. DataAccess.. DataAdapter, SQL Server CheckedListBox1. Form1 [ 10.5] UseDataSet_Click ( ). Private Sub UseDataSet_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles UseDataSet.Click ' CheckedListBox. CheckedListBox1.Items.Clear() 356

' Connection. Dim cn As New SqlConnection( _ "Server=(local)\NetSDK;DataBase=pubs;" _ & "Integrated Security=SSPI") ' SqlDataAdapter. ' SQL Connection. Dim da As SqlDataAdapter = New SqlDataAdapter _ ("SELECT au_id, au_lname + ', ' + au_fname As FullName FROM Authors", cn) ' DataSet. Dim ds As DataSet = New DataSet("Authors") da.fill(ds, "Authors") ' DataRow. Dim dr As DataRow 10 Chapter ' DataSet ' CheckedListBox. For Each dr In ds.tables("authors").rows CheckedListBox1.Items.Add(dr("FullName")) Next End Sub private void UseDataSet_Click(object sender, System.EventArgs e) { // checkedlistbox. checkedlistbox1.items.clear(); // Connection. SqlConnection cn = new SqlConnection(@"Server=(local)\NetSDK;DataBase=pubs; Integrated Security=SSPI"); // SqlDataAdapter. // SQL Connection. SqlDataAdapter da = new SqlDataAdapter("SELECT au_id, au_lname + ', ' + au_fname 357

As FullName FROM Authors", cn); // DataSet SqlDataAdapter. DataSet ds = new DataSet("Authors"); da.fill(ds, "Authors"); } // DataSet // CheckedListBox. foreach (DataRow dr in ds.tables["authors"].rows) { checkedlistbox1.items.add(dr["fullname"]); } CheckedListBox1 SelectedIndexChanged. ListBox1_SelectedIndexChanged,. CheckedListBox GetItemChecked., Form1 CheckedListBox1, SelectedIndex Changed [ 10.6] ( ). Private Sub CheckedListBox1_SelectedIndexChanged _ (ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ HandlesCheckedListBox1.SelectedIndexChanged ' CheckedListBox1 Label1. Label1.Text = "CheckedListBox1_SelectedIndexChanged" ' CheckedListBox1 Label2. Label2.Text = CheckedListBox1.Items(CheckedListBox1.SelectedIndex) ' CheckedListBox1. Label3.Text = "Checked = " & CheckedListBox1.GetItemChecked _ (CheckedListBox1.SelectedIndex) 358

End Sub private void checkedlistbox1_selectedindexchanged(object sender, System.EventArgs e) { // checkedlistbox1 Label1. label1.text = "CheckedListBox1_SelectedIndexChanged"; // checkedlistbox1 Label2. label2.text = checkedlistbox1.text; // checkedlistbox1. label3.text = "Checked = " + checkedlistbox1.getitemchecked(checkedlistbox1.selectedindex); } 10 Chapter F5 [ 10.5]. [ 10.5] UseDataSet_Click SqlDataAdapter. SQL Select Connection. DataSet, SqlDataAdapter Fill ( ). Fill DataTable, 359

Authors. DataTable, ( ) DataSet. DataSet DataTable., DataSet, DataTable. DataSet DataTable,. (For ~ Each ) DataTable DataRow (DataRow ). DataRow. [ 10.5] FullName CheckedListBox., DataSet. DataSet DataTable. DataTable SQL, 16,777,216 (row) ( ). DataRow DataTable, DataTable. DataSet DataTable DataRow. [ 10.6]. 360

DataSet.. Visual Basic 6. Visual Studio.NET. Visual Basic 6. 10 Chapter,.,, XML,.,.,,.,.. (DisplayMember ValueMember ) 11 Visual Studio.NET Visual Studio.NET. ADO.NET ComboBox DataGrid DataSet. 361

, (simple) (complex). DataSet, DataSource DataSet.., List Grid. TextBox. DataBindings (Control ), Add DataSet. ' Connection. Dim cn As New SqlConnection( _ "Server=(local)\NetSDK;DataBase=northwind;" _ & "Integrated Security=SSPI") ' SqlDataAdapter. ' SQL Connection. Dim da As SqlDataAdapter = New SqlDataAdapter _ ("SELECT * from Customers", cn) ' DataSet. Dim ds As DataSet = New DataSet("Customers") ' DataSet Fill. da.fill(ds, "Customers") ' TextBox DataBinding. TextBox2.DataBindings.Add("Text", ds.tables("customers"), "CompanyName") TextBox3.DataBindings.Add("Text", ds.tables("customers"), "Address") TextBox4.DataBindings.Add("Text", ds.tables("customers"), "City") 362

// Connection. SqlConnection cn = new SqlConnection(@"Server=(local)\NetSDK;DataBase=northwind;Integrate d Security=SSPI"); // SqlDataAdapter. // SQL Connection. SqlDataAdapter adp = new SqlDataAdapter("SELECT * from Customers", cn); // DataSet. DataSet ds = new DataSet("Customers"); // DataSet Fill. adp.fill(ds, "Customers"); 10 Chapter // TextBox DataBinding. textbox2.databindings.add("text", ds.tables["customers"], "CompanyName"); textbox3.databindings.add("text", ds.tables["customers"], "Address"); textbox4.databindings.add("text", ds.tables["customers"], "City"); DataAccess, ComboBox DataGrid. ComboBox DisplayMember ValueMember. DisplayMember ComboBox (DataSet ), ValueMember ( primary ). Authors primary au_id, ValueMember au_id.,. Form1, BindWithDataSet_Click [ 10.7] ( ). 363

Private Sub BindWithDataSet_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles BindWithDataSet.Click Dimcn As New SqlConnection( _ "Server=(local)\NetSDK;DataBase=pubs;" _ & "Integrated Security=SSPI") Dimda As SqlDataAdapter = New SqlDataAdapter _ ("SELECT au_id, au_lname + ', ' + au_fname As FullName FROM Authors", cn) Dimds As DataSet = New DataSet("Authors") da.fill(ds, "Authors") With ComboBox1 ' ComboBox DataSource ' DataSet Authors DataTable..DataSource = ds.tables("authors") ' ComboBox DisplayMember DataSet FullName..DisplayMember = "FullName" ' ComboBox ValueMember au_id (DataTable primary )..ValueMember = "au_id" End With End Sub private void BindWithDataSet_Click(object sender, System.EventArgs e) { combobox1.items.clear(); SqlConnection cn = 364

new SqlConnection(@"Server=(local)\NetSDK;DataBase=pubs;Integrated Security=SSPI"); SqlDataAdapter da = new SqlDataAdapter("SELECT au_id, au_lname + ', ' + au_fname As FullName FROM Authors", cn); DataSet ds = new DataSet("Authors"); da.fill(ds, "Authors"); // combobox DataSource // DataSet Authors DataTable. combobox1.datasource = ds.tables["authors"]; // combobox DisplayMember DataSet FullName. combobox1.displaymember = "FullName"; 10 Chapter } // combobox ValueMember au_id (DataTable primary ). combobox1.valuemember = "au_id"; [ 10.5] [ 10.6] ListBox, ListBox Label. DataSet. [ 10.7] (ComboBox).,. ComboBox? [ 10.8]. ComboBox1 SelectedIndexChanged Label. ComboBox1 ( ). Visual Basic.NET C#., ComboBox. 365

Private Sub ComboBox1_SelectedIndexChanged( _ ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles ComboBox1.SelectedIndexChanged ' ComboBox1 Label1. Label1.Text = "ComboBox1_SelectedIndexChanged DataBound" ' ComboBox1 Label2. Label2.Text = ComboBox1.Text ' ComboBox1. Dimitm As DataRowView itm = ComboBox1.SelectedItem Label3.Text = CType(itm("au_id"), String) End Sub F5, [ 10.7]. 366

, DisplayMember Authors DataTable FullName ComboBox1. ComboBox1 SelectedIndexChanged ValueMember au_id. DataAccess, DataGrid DataSet., DataGrid ComboBox TabPage2.. 1., (DataGrid Binding) TabPage2. 10 Chapter 2. ComboBox TabPage2. 3. DataGrid TabPage2. [ 10.8]. DataSet DataGrid. ComboBox 3. 367

DataGrid Binding DataGrid, TabControl1 TabIndexChanged. TabControl1, TabControl1_TabIndexChanged [ 10.9] ( ). TabControl. Northwind Orders DataGrid. Private Sub TabControl1_TabIndexChanged _ (ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles TabControl1.SelectedIndexChanged '. ', DataGrid. ' 0 1. IfTabControl1.SelectedTab.TabIndex = 1 Then ' Connection. Dim cn As New SqlConnection( _ "Server=(local)\NetSDK;DataBase=northwind;" _ & "Integrated Security=SSPI") ' SqlDataAdapter. ' SQL Connection. Dim da As SqlDataAdapter = New SqlDataAdapter _ ("SELECT * from Orders", cn) ' SqlDataAdapter ' DataSet. Dim ds As DataSet = New DataSet("Orders") ' Fill DataSet. da.fill(ds) ' DataSet 368

' DataGrid DataSource. DataGrid1.DataSource = dv End If End Sub private void tabcontrol1_tabindexchanged(object sendert, System.EventArgs e) { //. //, DataGrid. if(tabcontrol1.selectedtab.text == "DataGrid Binding") { // Connection. SqlConnection cn = new SqlConnection(@"Server=(local)\NetSDK;DataBase=northwind; Integrated Security=SSPI"); 10 Chapter // SqlDataAdapter. // SQL Connection. SqlDataAdapter da = new SqlDataAdapter("SELECT * from Orders", cn); // SqlDataAdapter // DataSet. DataSet ds = new DataSet("Orders"); // Fill DataSet. da.fill(ds); // DataSet // DataGrid DataSource. datagrid1.datasource = ds; } } 369

SqlDataAdapter. Connection Command, DataAdapter Fill. [ 10.9], DataGrid DataSource DataSet. F5. [ 10.9]., DataGrid SQL Server.,.,. Summary ADO.NET. FCL,. ADO.NET.,. ADO.NET,., DataReader. 370

DataSet DataAdapter. 11 Visual Studio.NET ADO.NET. Q & A Q A DataReader., IList IListSource (System.ComponentModel ). DataReader unbuffered,.,. 10 Chapter Q A,.. connection open,, close. DataReader..NET DataReader. DataSet.. Select, Insert, Update, Delete SQL. SQL. 371

Qui z 1. DataReader DataAdapter SQL ADO.NET? 2. DataReader.? 3. SqlDataAdapter OleDataAdapter.,? 4. DataAdapter Connection.,? 5..NET Label, DataGrid, TextBox DataSet XML.,? 6.? 1. 2. 3. 4. 5. 6. Exercises 1. DataAccess TabPage1 ShowCheckedItems.., CheckedListBox 372

. GetItemChecked. Visual Studio.NET (SDK ). 2. DataAccess TabPage2 ComboBox. ComboBox. Northwind Customers TabPage2 ComboBox2 DataGrid CustomerID ComboBox2 CustomerID DataGrid., Form1 DataView dv. Public Class Form1 Inherits System.Windows.Forms.Form Private dv As DataView 10 Chapter public class Form1 : System.Windows.Forms.Form { private DataView dv; DataView Form1, Form1. Load_Customers. BindWithDataSet_ Click.,., Pubs Authors Northwind Customers. Load_Customers. Northwind Connection. Customers SQL Select SqlDataAdapter. SqlDataAdapter Fill, DataSet DataTable Customers. 373

ComboBox2 DataSet. ComboBox2 ValueMember CustomerID. ComboBox2 DisplayMember CustomerID. ComboBox2 SelectedIndexChanged, DataView RowFilter DataView, DataView DataGrid. SelectedIndexChanged. Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged ' DataView RowFilter. dv.rowfilter = "CustomerID Like '" & ComboBox2.Text & "% " ' DataGrid DataView. DataGrid1.DataSource = dv End Sub private void combobox2_selectedindexchanged(object sender, System.EventArgs e) { // DataView RowFilter. dv.rowfilter = "CustomerID Like '" + combobox2.text + "% "; } // DataGrid DataView. datagrid1.datasource = dv;, TabControl1_TabIndexChanged., DataGrid DataSet DataView.. 374

dv = New DataView(ds.Tables(0), "", "", DataViewRowState.OriginalRows) ' DataSet ' DataGrid DataSource. DataGrid1.DataSource = dv SDK DataView., DataView DataSet. [ 10.10]. 10 Chapter 375