APress - Database Programming with C# (2002)(1).pdf
(
3995 KB
)
Pobierz
Database Programming with C#
Database Programming with C#
Database Programming with C#
Table of Contents
Database Programming with C#......................................................................................................................1
Introduction........................................................................................................................................................4
Who This Book Is For............................................................................................................................4
How This Book Is Organized.................................................................................................................4
Technology Requirements......................................................................................................................4
Example Code.........................................................................................................................................5
Data Source.............................................................................................................................................5
Feedback.................................................................................................................................................5
Chapter 1: A Lightning−Quick Introduction to C#........................................................................................6
Overview.................................................................................................................................................6
Reviewing Programming Concepts........................................................................................................6
A Quick Look at Components of the .NET Framework..................................................................7
JIT: Another Word for Virtual Machine?.......................................................................................10
Assemblies and Namespaces..........................................................................................................10
The .NET Framework Class Library..............................................................................................13
Getting Cozy with the VS .NET Integrated Development Environmen..............................................13
All Languages Share the IDE.........................................................................................................14
Two Interface Modes......................................................................................................................14
Built−in Web Browser Functionality.............................................................................................15
Command Window.........................................................................................................................15
Built−in Object Browser................................................................................................................16
Integrated Debugger.......................................................................................................................17
Integrated Help System..................................................................................................................17
Macros............................................................................................................................................18
Upgraded Deployment Tools.........................................................................................................19
Text Editors....................................................................................................................................19
IDE and Tools Modification...........................................................................................................20
Server Explore...............................................................................................................................20
Data Connections...........................................................................................................................21
Toolbox..........................................................................................................................................21
Task List.........................................................................................................................................22
Summary...............................................................................................................................................22
Chapter 2: Using Databases............................................................................................................................23
Overview...............................................................................................................................................23
What Is a Database?..............................................................................................................................23
Why Use a Database?...........................................................................................................................23
Relational vs. Hierarchica....................................................................................................................24
Hierarchical Databases...................................................................................................................24
Relational Databases......................................................................................................................25
What C# Programmers Need to Know About Relational Databases....................................................25
UserMan Database Schema..................................................................................................................36
Summary...............................................................................................................................................37
i
Database Programming with C#
Table of Contents
Chapter 3A: Presenting ADO.NET: The Connected Layer........................................................................38
Overview...............................................................................................................................................38
Data−Related Namespaces...................................................................................................................40
Data Providers and Drivers...................................................................................................................40
Specifying a Provider or Driver When Connecting.......................................................................42
.NET Data Providers......................................................................................................................42
The Connection Class.....................................................................................................................43
ConnectionString Property.............................................................................................................44
Connection Class Properties...........................................................................................................53
Connection Class Methods.............................................................................................................55
Connection Class Events................................................................................................................58
Opening a Connection....................................................................................................................59
Closing a Connection.....................................................................................................................60
Disposing of a Connection.............................................................................................................60
Comparing Two Connection Objects.............................................................................................60
Manipulating the Connection State................................................................................................61
Pooling Connections.......................................................................................................................63
Handling Provider, Driver, and Data Source Messages.................................................................67
Transactions....................................................................................................................................68
Handling Connection Class Exceptions.........................................................................................76
Using Command Objects......................................................................................................................85
OleDbCommand, OdbcCommand, and SqlCommand...................................................................86
Command Class Properties............................................................................................................89
Command Class Methods...............................................................................................................95
Executing a Command...................................................................................................................96
Handling Command Class Exceptions...........................................................................................98
Using the DataReader Class................................................................................................................100
SqlDataReader, OdbcDataReader, and OleDbDataReader..........................................................101
Declaring and Instantiating a DataReader Object........................................................................101
Reading Rows in a DataReader....................................................................................................102
Closing a DataReader...................................................................................................................102
Checking for Null Values in Columns.........................................................................................103
Handling Multiple Results............................................................................................................103
DataReader Properties..................................................................................................................104
DataReader Methods....................................................................................................................104
Handling DataReader Exceptions................................................................................................110
When to Use the DataReader Class..............................................................................................110
XmlReade....................................................................................................................................110
XmlReader Properties..................................................................................................................111
XmlReader Methods.....................................................................................................................112
Declaring and Instantiating an XmlReader Objec.......................................................................115
Reading Rows in an XmlReader..................................................................................................116
Closing an XmlReader.................................................................................................................116
Handling XmlReader Exceptions.................................................................................................116
The DataAdapter Explained................................................................................................................117
DataAdapter Properties................................................................................................................118
DataAdapter Methods...................................................................................................................119
DataAdapter Events......................................................................................................................119
ii
Database Programming with C#
Table of Contents
Chapter 3A: Presenting ADO.NET: The Connected Layer
Instantiating a DataAdapter..........................................................................................................120
Setting the Command Properties..................................................................................................122
Handling Fill Operation Errors.....................................................................................................126
Handling Row Updates................................................................................................................127
Using the CommandBuilder Class......................................................................................................129
When to Use the CommandBuilder Class....................................................................................129
Preparing the DataAdapter...........................................................................................................130
Summary.............................................................................................................................................131
Chapter 3B: Presenting ADO.NET: The Disconnected Layer..................................................................133
Using the DataSet Class......................................................................................................................133
Recordset vs. DataSe...................................................................................................................134
DataSet Properties........................................................................................................................135
DataSet Methods..........................................................................................................................138
DataSet Events.............................................................................................................................140
Instantiating a DataSe..................................................................................................................141
Populating Your DataSet Using the DataAdapter........................................................................142
Updating Your Data Source Using the DataAdapter...................................................................144
Clearing Data from a DataSet......................................................................................................146
Copying a DataSe........................................................................................................................146
Merging Data in a DataSet with Other Data................................................................................146
Detecting and Handling Changes to Data in a DataSe................................................................148
Accepting or Rejecting Changes to Data in a DataSet.................................................................150
Using the DataTable Class..................................................................................................................152
DataTable Properties....................................................................................................................152
DataTable Methods......................................................................................................................154
DataTable Events.........................................................................................................................156
Declaring and Instantiating a DataTable......................................................................................157
Building Your Own DataTable....................................................................................................157
Populating a DataTable................................................................................................................159
Clearing Data from a DataTable..................................................................................................159
Copying a DataTable....................................................................................................................159
Searching a DataTable and Retrieving a Filtered Data View......................................................160
Copying Rows in a DataTable......................................................................................................161
Examining the Order of Column and Row Change Events..........................................................163
Handling Column Changes..........................................................................................................163
Handling Row Changes................................................................................................................164
Handling Row Deletions..............................................................................................................166
Using the DataView Class..................................................................................................................167
DataView Properties.....................................................................................................................167
DataView Methods.......................................................................................................................168
DataView Events..........................................................................................................................169
Declaring and Instantiating a DataView......................................................................................170
Searching a DataView..................................................................................................................170
Sorting a DataView......................................................................................................................171
Using the DataRow Class...................................................................................................................172
Declaring and Instantiating a DataRow........................................................................................174
iii
Database Programming with C#
Table of Contents
Chapter 3B: Presenting ADO.NET: The Disconnected Layer
Building Your Own DataRow......................................................................................................175
Using the DataColumn Class..............................................................................................................175
Declaring and Instantiating a DataColumn..................................................................................176
Using the DataRelation Class.............................................................................................................177
Declaring and Instantiating a DataRelation..................................................................................178
Looking at Cursors..............................................................................................................................183
Cursor Location............................................................................................................................184
Cursor Types................................................................................................................................184
Examining Data Source Locking........................................................................................................186
Pessimistic Locking......................................................................................................................186
Optimistic Locking.......................................................................................................................188
Using "Classic" ADO and COM Interop............................................................................................194
Summary.............................................................................................................................................195
Chapter 4: Presenting the IDE From a Database Viewpoint....................................................................197
Using the Server Explorer...................................................................................................................197
Handling Data Connections..........................................................................................................197
Handling Servers..........................................................................................................................200
Looking at Database Projects..............................................................................................................206
Creating a Database Project Folder..............................................................................................208
Deleting a Database Project Folder..............................................................................................208
Adding Database Objects to a Database Project..........................................................................209
Designing Databases with Visio for Enterprise Architect..................................................................212
Designing Databases with the Database Designer..............................................................................212
Creating a Database Diagram.......................................................................................................213
Saving the Database Diagram......................................................................................................218
Using the Table Designe....................................................................................................................218
Adding Columns...........................................................................................................................218
Setting the Primary Key...............................................................................................................219
Adding Indexes and Keys.............................................................................................................219
Adding Constraints.......................................................................................................................220
Creating a Relationship................................................................................................................222
Designing Queries with the Query Designer......................................................................................222
Taking a Closer Look at the Query Designer Panes....................................................................223
Verifying the SQL Syntax............................................................................................................227
Executing a Query........................................................................................................................228
Examining the Various Query Types...........................................................................................228
Script Editing Using the SQL Editor..................................................................................................230
Using the Query Editor to Produce SQL Statements...................................................................231
Saving a Scrip..............................................................................................................................232
Editing and Using Script Templates.............................................................................................232
Running SQL Scripts....................................................................................................................232
Creating Typed Data Sets...................................................................................................................233
Using the XML Designer to Create a Typed Data Set.................................................................233
Using the DataSet Designer to Create a Typed Data Set.............................................................233
Summary.............................................................................................................................................235
iv
Plik z chomika:
bomaszko
Inne pliki z tego folderu:
Język C#- szybki kurs.pdf
(388 KB)
C# Porady i metody- Charles Wright, Kris Jamsa [NAKOM](1).pdf
(102116 KB)
wzorce projektowe w C#.ppt
(3523 KB)
C# Ksiega Przykladow - Allen Jones [A.P.N. Promise].pdf
(125122 KB)
Sekrety języka C# - A. Stefańczyk.pdf
(3937 KB)
Inne foldery tego chomika:
_ Basic _ QBasic ---
_ DOS _---
_ EDYTORY - IDE - GUI
_ EMULATORY - interpretery
_ LITERATURA
Zgłoś jeśli
naruszono regulamin