Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ado.ne twith csharpinhindi

689 views

Published on

hindi

Published in: Education
  • Login to see the comments

Ado.ne twith csharpinhindi

  1. 1. ADO.NET With C# in Hindi B c c F a l n a . c o m 0 9 7 9 9 4 - 5 5 5 0 5 Kuldeep Chand I have tried my best to compile each and every aspect related to ADO.NET with C# Programming Language in this eBook with various kinds of Professional Level Console and Windows Forms Based Example Programs like Creating Single Forms and Master/Detail Forms using Visual Studio’s Wizard and Manual Coding. It have latest content on ADO.NET and I have tried my best to clear each and every concept in as easy language as possible with Console/Windows Forms Example Program. I believe that no other ADO.NET with C# Book in Hindi Language has as much and good content as in this eBook is in Hindi Language because I have tried my best to include each and every concept related to ADO.NET and I wish, each and every buyer would be happy with the content of this eBook. If you read this EBook, you will sure get Good Understanding of ADO.NET and would be in better situation to develop a Professional Level Database Application easily.
  2. 2. 1 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET with C# in Hindi Kuldeep Mishra BetaLab Computer Center Falna
  3. 3. 2 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET in HINDI Copyright © 2013 by Kuldeep Chand All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editors: Kuldeep Chand Distributed to the book trade worldwide by BetaLab Computer Center, Behind of Vidhya Jyoti School, Falna Station Dist. Pali (Raj.) Pin 306116 e-mail bccfalna@gmail.com, or visit http://www.bccfalna.com. For information on translations, please contact BetaLab Computer Center, Behind of Vidhya Jyoti School, Falna Station Dist. Pali (Raj.) Pin 306116 Mob.: 097994-55505 The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, the author shall not have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this book.
  4. 4. 3 www.BccFalna.com ADO.NET with C# in Hindi This book is dedicated to you if you really wants to become a Professional Developer
  5. 5. 4 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET with C# Index of contents
  6. 6. 5 www.BccFalna.com ADO.NET with C# in Hindi Table of Contents ADO.NET – Introduction........................................................................................ 12 What is ADO.NET................................................................................................ 14 ADO – The ActiveX Data Object Limitations ........................................................ 15 Connected Objects .............................................................................................. 17 Connection Object............................................................................................ 17 Transaction Object ........................................................................................... 18 DataAdapter Object.......................................................................................... 18 Command Object ............................................................................................. 19 Parameter Object ............................................................................................. 19 DataReader Object........................................................................................... 19 Disconnected Objects.......................................................................................... 19 DataSet Object................................................................................................. 20 DataTable Object ............................................................................................. 20 DataRow Object ............................................................................................... 20 DataColumn Object .......................................................................................... 21 DataView Object............................................................................................... 21 Constraints Object............................................................................................ 21 DataRelation Object ......................................................................................... 21 .NET Data Providers............................................................................................ 22 Using ProviderBase Model ............................................................................... 26 Third-Party Data Providers ............................................................................... 30 System.Data.Design Namespace ........................................................................ 32 ADO.NET – Object Model...................................................................................... 34 DbConnection – To Establish Connection............................................................ 35 DbCommand – To Execute Command................................................................. 38 DbParameter – To Create Parameterized Commands......................................... 39 DataSet – Holding Disconnected Data................................................................. 42 DataReader and DataAdapter – To Fetch Resultset ............................................ 44 DbDataReader – To Fetch Data in Connected Way ......................................... 45 DbDataAdapter – Bridge between Connected and Disconnected..................... 46 ADO.NET – Exception Handling .......................................................................... 47 Disconnected Stack Exceptions ....................................................................... 48 Provider Specific Exceptions ............................................................................ 48 SqlType Specific Exception .............................................................................. 49 Other ADO.NET Exceptions ............................................................................. 49 Summary of ADO.NET Data Model...................................................................... 49 IDbConnection Interface................................................................................... 50 IDbTransaction Interface .................................................................................. 51 IDbCommand Interface .................................................................................... 51 IDbDataParameter and IDataParameter Interfaces .......................................... 52 IdbDataAdapter and IDataAdapter Interfaces ................................................... 53 IDataReader and IDataRecord Interfaces......................................................... 53 Data Provider Abstraction Using Interface........................................................ 55 Using Application Configuration File................................................................. 55 ADO.NET – Connection Object............................................................................. 58 Working with ADO.NET Connection..................................................................... 69
  7. 7. 6 www.BccFalna.com ADO.NET with C# in Hindi Creating Connection Objects ............................................................................... 70 DbConnectionStringBuilder.................................................................................. 76 IDbConnection..................................................................................................... 80 BeginTransaction() Method .............................................................................. 81 ChangeDatabase() Method .............................................................................. 81 Open() Method ................................................................................................. 81 CreateCommand() Method............................................................................... 82 ConnectionString Property................................................................................ 82 ConnectionTimeout Property............................................................................ 82 Database Property ........................................................................................... 82 State Property .................................................................................................. 82 DbConnection Class ............................................................................................ 83 Connection Pooling.............................................................................................. 83 ADO.NET – Command Object............................................................................... 88 Retrieving Single Result with ExecuteScalar() Method......................................... 88 Creating Command Object ............................................................................... 88 Configuring Command Object .......................................................................... 89 Executing Command ........................................................................................ 91 Retrieving Resultset with ExecuteReader() Method ............................................. 94 IDataRecord Interface ...................................................................................... 94 Common Behavior Parameters of ExecuteReader() Method ............................ 98 Querying Resultset for Storage.......................................................................... 103 Executing Command Asynchronously................................................................ 112 Working with Connected Layer Only ................................................................. 116 Working with Connection Object ........................................................................ 117 BeginTransaction() ......................................................................................... 118 ChangeDatabase()......................................................................................... 118 ConnectionTimeout()...................................................................................... 118 GetSchema().................................................................................................. 118 Database........................................................................................................ 118 DataSource .................................................................................................... 118 State............................................................................................................... 118 Working with Command Object.......................................................................... 121 CommandTimeout.......................................................................................... 122 Connection..................................................................................................... 122 Parameters..................................................................................................... 122 Cancel().......................................................................................................... 122 ExecuteReader() ............................................................................................ 122 ExecuteNonQuery()........................................................................................ 122 ExecuteScalar().............................................................................................. 123 Prepare()........................................................................................................ 123 Working with DataReader Object....................................................................... 123 Accessing Multiple Resultsets ........................................................................ 125 Updating Changes in Underlying Database........................................................ 127 Structuring Common Task’s Library................................................................ 128 Adding Connection Logic................................................................................ 129 Adding Insertion Logic.................................................................................... 131 Adding Deletion Logic..................................................................................... 134 Adding Update Logic ...................................................................................... 135 Adding Selection Logic................................................................................... 136 Parameterized Command Object....................................................................... 139
  8. 8. 7 www.BccFalna.com ADO.NET with C# in Hindi SQL Injection Attack....................................................................................... 140 DbParameter Members .................................................................................. 142 Implementing Standard SQL Queries............................................................. 145 Parameters with Other Data Providers ........................................................... 147 Executing Stored Procedures......................................................................... 147 ADO.NET – DataSets Object ............................................................................... 154 Features of Disconnected Scenario Object ........................................................ 155 Serializable..................................................................................................... 155 XML Supported .............................................................................................. 155 History of Changes Maintainable.................................................................... 156 Architecture of DataSet Object........................................................................... 157 Tables Property.............................................................................................. 158 Relations Property.......................................................................................... 158 ExtendedProperties Property.......................................................................... 158 DataTable Object............................................................................................... 159 Columns Property........................................................................................... 160 Rows Property................................................................................................ 160 Constraints Property....................................................................................... 160 DataColumn Object............................................................................................ 160 Add() .............................................................................................................. 161 Add("ColumnName") ...................................................................................... 161 Add(PreExistingDataColumnName) ............................................................... 161 Add("SubTotal", Type.GetType("System.Single", "Sum(Price)")..................... 161 DataRow Object................................................................................................. 162 Constraints Object ............................................................................................. 164 ForeignKeyConstraint..................................................................................... 164 UniqueConstraint............................................................................................ 165 PrimaryKey Property.......................................................................................... 165 DataTable Events .............................................................................................. 166 ColumnChanging Event.................................................................................. 166 ColumnChanged Event .................................................................................. 166 RowChanging Event....................................................................................... 166 RowChanged Event........................................................................................ 166 RowDeleting Event......................................................................................... 167 RowDeleted Event.......................................................................................... 167 TableClearing Event....................................................................................... 167 TableCleared Event........................................................................................ 167 TableNewRow Event...................................................................................... 167 DataColumnChangeEventArgs Properties...................................................... 167 DataRowChangeEventArgs Properties........................................................... 168 DataTableClearTableEventHandler Properties............................................... 168 DataTableNewRowEventHander Properties................................................... 169 Relational Data .................................................................................................. 176 Relations Collection........................................................................................ 176 Working with DataSet Object.......................................................................... 178 Strongly Typed DataSets ................................................................................... 184 Building Strongly Typed DataSets .................................................................. 186 ADO.NET – DataAdapter Object ......................................................................... 197 What is DataAdapter.......................................................................................... 197 DataAdapter Architecture................................................................................... 198 Using DataAdapter............................................................................................. 199
  9. 9. 8 www.BccFalna.com ADO.NET with C# in Hindi Accessing Single Table Data with Visual Studio............................................. 200 Accessing Single Table Data with Manual Coding.......................................... 211 Accessing Multiple Table Data to Fill DataSets............................................... 217 Database Schema Query................................................................................... 227 Mapping............................................................................................................. 234 MissingMappingAction and MissingSchemaAction ......................................... 249 ADO.NET – Data Updating .................................................................................. 252 Updating Table : Drag-and-Drop Approach........................................................ 252 Using Visual Designer Properly ...................................................................... 260 Master/Detail or Parent/Child Using Drag-and-Drop ....................................... 264 CommandBuilder Object.................................................................................... 271 State Management............................................................................................. 277 Detached (1) .................................................................................................. 278 UnChanged (2)............................................................................................... 279 Added (4) ....................................................................................................... 279 Deleted (8) ..................................................................................................... 279 Modified (16) .................................................................................................. 279 SqlBulkCopy Class ............................................................................................ 288 Disconnected Data Editing................................................................................. 291 Adding New Rows (Records).......................................................................... 292 Modifying Existing Row (Records).................................................................. 293 Deleting Existing Row (Records) .................................................................... 294 Disconnected Data History Handling.................................................................. 295 Current Constant............................................................................................ 296 Original Constant............................................................................................ 296 Proposed Constant......................................................................................... 296 Default Constant............................................................................................. 296 Concurrency Understanding .............................................................................. 298 Pessimistic Concurrency ................................................................................ 299 Optimistic Concurrency .................................................................................. 300 Concurrency Implementing ................................................................................ 301 Handling Null Values for DataSet ................................................................... 301 Handling Multiple Rows Updating................................................................... 303 ADO.NET – Transaction ...................................................................................... 306 What is Transaction in Programming ................................................................. 306 ACID Properties ............................................................................................. 307 Database Transactions................................................................................... 308 ADO.NET Transaction Support.......................................................................... 310 Transaction Class........................................................................................... 312 Creating Transactional Database Application..................................................... 314 Implementing Transactions............................................................................. 315 Isolation Level Effect.......................................................................................... 322 Isolation Levels............................................................................................... 322 Isolation Levels of ADO.NET.......................................................................... 323 Working with Disconnected Layer Only ............................................................ 329 Working with DataSet Object ............................................................................. 331 DataSet Properties ......................................................................................... 332 DataSet Methods............................................................................................ 333 Working with DataColumn Object ...................................................................... 335 AllowDBNull Property ..................................................................................... 336 AutoIncrement Property.................................................................................. 336
  10. 10. 9 www.BccFalna.com ADO.NET with C# in Hindi AutoIncrementSeed Property ......................................................................... 336 AutoIncrementStep Property .......................................................................... 336 Caption Property ............................................................................................ 336 ColumnMapping Property............................................................................... 336 ColumnName Property................................................................................... 337 DataType Property ......................................................................................... 337 DefaultValue Property .................................................................................... 337 Expression Property ....................................................................................... 337 Ordinal Property ............................................................................................. 337 ReadOnly Property......................................................................................... 337 Table Property................................................................................................ 337 Unique Property ............................................................................................. 338 Working with DataRow Object............................................................................ 340 DataRow Members......................................................................................... 340 RowState Property in Detail............................................................................ 345 DataRowVersion Property in Detail ................................................................ 349 Working with DataTable Object.......................................................................... 350 DataTable Members....................................................................................... 350 Inserting DataTables into DataSet Object....................................................... 352 Obtaining Data in DataSet Object................................................................... 355 Processing DataTable Data Using DataTableReader Object.......................... 356 XML Serialization of DataTable/DataSet Objects............................................ 358 Binary Serialization of DataTable/DataSet Objects......................................... 373 Working with DataAdapter Object ...................................................................... 374 DataAdapter Members ................................................................................... 374 Creating Library for Common Disconnected Functionality.................................. 378 Configuring DataAdapter................................................................................ 379 GetAllProducts() Method Implementation ....................................................... 381 UpdateProducts() Method Implementation ..................................................... 381 Handling Multi-Table DataSet Object with Relationship...................................... 390 Configuring DataAdapter Objects ................................................................... 391 Configuring Relationships between DataTable ............................................... 395 Updating Underlying Database Tables ........................................................... 397 Navigation between Related Tables ............................................................... 399 Working with Strongly Typed DataSet using Data Source.................................. 405 Understanding the App.config Configuration File............................................ 408 Understanding the Strongly Typed DataSet.................................................... 409 Understanding the Strongly Typed DataTable ................................................ 411 Understanding the Strongly Typed DataRow.................................................. 415 Understanding the Strongly Typed DataAdapter............................................. 416 Working with Strongly Typed DataSet Using Server Explorer ............................ 420 Selecting Data with Generated Code.............................................................. 423 Inserting New Record with Generated Code................................................... 428 Deleting Record with Generated Code ........................................................... 434 Invoking Stored Procedures using Generated Code....................................... 441 ADO.NET – Searching, Sorting and Filtering..................................................... 446 Strongly Typed DataSet Object Setup using Designer ....................................... 447 Working with DataTable Object.......................................................................... 449 Finding Single Required Row ......................................................................... 450 Retrieving Multiple Rows ................................................................................ 454 Adding Calculated Column ............................................................................. 458 Performing Aggregate Calculation.................................................................. 460
  11. 11. 10 www.BccFalna.com ADO.NET with C# in Hindi Working with DataRelation Object – Strongly Typed DataSet ............................ 463 Working with DataRelation Object – Simple DataSet ......................................... 476 Working with DataView Object........................................................................... 489 Creating DataView ......................................................................................... 489 Converting DataView to DataTable................................................................. 496 Last but Not Least ............................................................................................... 498
  12. 12. 11 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET Introduction
  13. 13. 12 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET – Introduction Computer dks ,d Information Storage o Processing Machine ekuk tk ldrk gSA pwafd gj Application dh t:jr vyx izdkj dh gksrh gS] ftldh otg ls mlds Data Hkh vyx izdkj ds gksrs gSaA blfy, ge lHkh izdkj ds Data dks leku rjhds ls Store o Handle ugha dj ldrsA mnkgj.k ds fy, Microsoft Word o Notepad esa ftl izdkj ds Text Data dks Handle fd;k tkrk gS] Accounting Related Software Tally ds Data dks Exactly mlh rjg ls Store o Manage ugha fd;k tk ldrkA ysfdu fdlh Hkh izdkj ds Data dks lkj.kh ds :i esa Manage djuk] Text ds :i esa Manage djus dh rqyuk esa T;knk vklku gksrk gSA blfy, T;knkrj Business Related Data dks lkj.kh ds :i esa gh Manage fd;k tkrk gSA D;ksafd Business Related Data ij le;≤ ij fofHkUu izdkj dh Calculations dks Perform fd;k tkrk gS vkSj Generate gksus okys Result ds vk/kkj ij gh fofHkUu izdkj ds t:jh Decisions fy, tkrs gSaA pwafd Computer Technology dk tc ls Commercialization gqvk gS] rc ls lcls T;knk ;fn dksbZ Application Develop fd;k x;k gS] rks og Database Related Application gh gS vkSj Computer Technology dk Commercialization djus dk ewy mÌs”; Hkh Business Purpose gh FkkA rkfd Business Related t:jh Decisions T;knk Accurate Data ds vk/kkj ij o T;knk rsth ls fy;k tk ldsA blhfy, orZeku le; esa Hkh Develop fd, tkus okys 95% ls T;knk Application Software, fdlh u fdlh rjg ds Business ls lEcaf/kr Database Management Application Software gh gSa] tks fdlh u fdlh Specific Type dh Business Requirement dks iwjk djus ds fy, gh Develop gks jgs gSa vkSj tSlkfd geus vHkh crk;k fd fdlh Hkh izdkj ds Data dh rjg Business Related Data dks Hkh lkj.kh ;kuh Tables ds :i esa Manage o Maintain djuk T;knk vklku o lqfo/kktud gksrk gS] blfy, Business Related Data dks T;knk vklkuh ls Access, Manipulate o Manage djus ds fy, fofHkUu izdkj ds Frontend o Backend Develop djus okyh Programming Languages o Software Develop fd, x, gSa] rkfd mUgsa vkil esa csgrj rjhds ls Integrate djds T;knk rsth ls GUI Business Applications Develop fd, tk ldsaA tc ge Business Applications dh ckr djrs gSa] rc lkekU;r% 2-Tier ;k 3-Tier Architecture vk/kkfjr Business Applications Develop fd, tkrs gSa rFkk fofHkUu izdkj ds Design o Development Patterns Use fd, tkrs gSaA gkykafd bu nksuksa gh rjg ds Development Architectures dks ljy “kCnksa Frontend o Backend ds uke ls tkuk tkrk gSA tgka Frontend fdlh Hkh Business Application dk og Part gksrk gS] ftlds ek/;e ls Develop fd, tkus okys Application Software ds lkFk User Interact djrk gSA tcfd Backend ds :i esa og DBMS Software gksrk gS] ftlesa Business Application ls lEcaf/kr Actual Data Stored jgrk gSA Frontend ds :i esa orZeku le; esa Java ;k .NET Based Programming Languages dks lokZf/kd Use fd;k tk jgk gS] tcfd Backend ds :i esa MSSQL Server, Oracle o
  14. 14. 13 www.BccFalna.com ADO.NET with C# in Hindi MySQL dks lcls T;knk Use fd;k tk jgk gSA gkykafd buds vykok Hkh dbZ vkSj Frontend o Backend Development Languages o DBMS Software Hkh Use fd, tkrs gSaA pwafd Frontend Programming Language o Backend Database nksuksa lkekU;r% vyx&vyx Programming Languages o Design Patterns ds vk/kkj ij Develop fd, tkrs gSa] blfy, ;s vkil esa ,d nwljs ds lkFk Directly Interaction djrs gq, Data dk ysu&nsu ugha dj ldrsA ftldh otg ls lkekU;r% buds chp ,d Driver Software (Data Access Library) Use fd;k tkrk gS] tks fd Frontend o Backend ds chp Connection Establish djus dk dke djrk gSA bl izfØ;k dks ge fuEu fp= }kjk csgrj rjhds ls le> ldrs gSa% Frontend Programming Language o Backend Data Source dks vkil esa Connect djus ds fy, tks Data Access Library Use fd;k tkrk gS] lkekU;r% og Data Access Library fofHkUu izdkj ds Backend Data Sources ds lkFk Frontend Programming Language ds chp Connection Establish djus dk dke dj ldrk gSA blfy, ,d gh Frontend Software dks vyx&vyx rjg ds Backend Database ds lkFk mi;ksx esa fy;k tk ldrk gSA ;kuh ;fn ge Oracle DBMS Software dks Backend ds :i esa Use djrs gSa] rks fdlh fo”ks’k Situation esa ge Oracle ds Data dks MSSQL Server DBMS Software esa Store dj ldrs gSa vkSj Frontend ds ek/;e ls Oracle ds LFkku ij SQL Server ls Data dks Access o Manipulate dj ldrs gSaA tcfd DBMS Software dks Change djus ds ckotwn gesa Frontend ds Backend ds lkFk Connection Establish djus okys Data Access Code dks Modify djus ds vykok vU; fdlh Hkh rjg dk Modification djus dh t:jr ugha gksrh gSA ADO.NET, Frontend o Backend ds chp Connection Establish djrs gq, buds chp ds vkilh Interaction dks Establish djus okyh Data Access Library gh gSA ;kuh ADO.NET ds ek/;e ls gh .NET Framework dh Frontend Programming Languages tSls fd C#.NET, VB.NET vkfn o Backend DBMS Software tSls fd MSSQL Server, MySQL, Oracle vkfn ds chp Data dk ysu&nsu lEHko gks ikrk gSA
  15. 15. 14 www.BccFalna.com ADO.NET with C# in Hindi What is ADO.NET ADO.NET, Microsoft.NET Framework dk ,d Part gS] tks fdlh File Based ;k Sever Based Data Source ls Frontend Application dks Communicate djokus dh lqfo/kk Provide djrk gS tcfd ADO.NET Library, .NET Framework ds System.Data uke ds Namespace ds vUrxZr gh Exist gksrh gSA bl Library esa mu Functionalities dks Define fd;k x;k gS] tks fdlh Data Source ls Connect gksus] Data Source ij Command Execute djus o Data Source esa Data dks Store, Manipulate o Delete djus dh lqfo/kk Provide djrs gSaA ADO.NET ds Role dks ge fuEu fp=kuqlkj csgrj rjhds ls le> ldrs gSa% ADO.NET (Active Data Object) dk fiNyk Version ADO (ActiveX Data Object) Fkk] tgka nksuksa esa ewy vUrj ;s gS fd ADO.NET gesa fdlh Data Source ds Data dks iwjh rjg ls Offline Mode esa Disconnected Data Cache dh rjg Access o Manipulate djus dh lqfo/kk Provide djrk gSA lkFk gh bl Disconnected lqfo/kk dks izkIr djus ds fy, ADO.NET ds fodkl ls igys RDO (Remote Data Object) dks Develop fd;k x;k FkkA Disconnected Data Access Technology dh t:jr orZeku le; esa blfy, cgqr T;knk gS D;ksafd orZeku esa ,d gh le; ij ,d gh Data Source ls cgqr lkjs Data dks Access o Manipulate fd;k tk jgk gksrk gSA ,sls esa Data dks ckj&ckj Database ls Retrieve djus o ckj&ckj Database esa Modified Data dks Update djus ls Data Access dh ftruh Demand gksrh gS] ml Demand dks iwjk ugha fd;k tk ldrk] D;ksafd Disc Access dh Speed vkt Hkh fdlh Hkh vU; Device dh rqyuk esa lcls de gSA Disconnected Data Source dh eq[; fo”ks’krk ;s gS fd Database dh ftl Table ds Data dks Access djuk gksrk gS ml Table ds Data dk ,d Copy Create gksdj Local Computer ij Cached gks tkrk gSA ifj.kkeLo:i Frontend Application }kjk tks Hkh Change fd;k tkrk gS] og Local Cache esa gh Save gksrk gSA bl Tabular Data ds Disconnected Container dks ADO.NET Library esa DataSet o DataTable Object }kjk Represent fd;k tkrk gS] ftuds ckjs esa ge vkxs foLrkj ls Discuss djsaxsA tc ge ADO o ADO.NET dh ckr djrs gSa] rc eq[; :i ls ,d ckr /;ku j[kuk gksrk gS fd ADO vkSj ADO.NET nksuksa ds dsoy uke gh feyrs&tqyrs gSaA tcfd bu nksuksa dh Internal Working dkQh vyx o ,d nwljs ls iwjh rjg ls fHkUu gSA blfy, bl ckr dks le>uk fd
  16. 16. 15 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET fdl izdkj ls ADO ls vyx rjg dh Functionality Provide djrk gS] gekjs fy, dkQh mi;ksxh gksrk gSA ADO.NET Architecture dks ge fuEu fp=kuqlkj T;knk csgrj rjhds ls Represent dj ldrs gS% ADO – The ActiveX Data Object Limitations ADO, Microsoft dh rjQ ls Data Access djus dh lcls Advance rduhd Fkh ftls Microsoft }kjk fdlh Hkh izdkj ds Data Source ls fdlh Hkh izdkj ds Data dks Access o Manipulate djus ds fy, Design o Develop fd;k x;k FkkA blhfy, tc .NET Framework dks Launch fd;k x;k] rks dsoy ADO dks gh fofHkUu izdkj ds Data Source ls Data Access djus ds fy, ADO.NET ds :i esa .NET Framework esa Implement fd;k x;k FkkA tcfd ftl le; ADO.NET Develop fd;k tk jgk Fkk] ml le; DAO, RDO, ODBCDirect o OleDb tSls dbZ vU; Data Access Technologies dks Hkh dkQh mi;ksx esa fy;k tkrk FkkA ADO dks ewy :i ls Unmanaged Code ds ek/;e ls Data Source ls Data dks Access o Manipulate djus ds fy, Design fd;k x;k FkkA tcfd .NET Framework esa Unmanaged Code dks Interop uke ds COM Object ds ek/;e ls Access o Manipulate djus ds fy,
  17. 17. 16 www.BccFalna.com ADO.NET with C# in Hindi Redefine fd;k x;k FkkA D;ksafd COM Object okLro esa DLL Hell uke dh ,d Specific Type dh ijs”kkuh dk f”kdkj Fkk vkSj ADO okLro esa ,d COM Based Component FkkA blfy, .NET Framework tSls Managed Code ds :i esa Design fd, x, Platform esa COM Based ADO dks T;ksa dk R;ksa mi;ksx esa ugha fy;k tk ldrk FkkA blhfy, Microsoft us ADO dks iwjh rjg ls Managed Codes ds vk/kkj ij Develop fd;kA ifj.kkeLo:i gesa ADO.NET ds :i esa ADO dk Latest Version izkIr gks ldkA blds vykok ADO dh ,d deh ;s Hkh Fkh dh ADO dks XML Data ds lkFk izfØ;k djus ds fy, Design ugha fd;k x;k FkkA blfy, ADO dks blfy, Hkh Modify djuk t:jh Fkk rkfd og XML Data ds lkFk lkekU; rjhds ls Processing dj ldsA D;ksafd XML ,d ,slk Standard ;k Universal Data Format gS] ftls dksbZ Hkh Application Software o Programming Language leku izdkj ls Access o Manipulate dj ldrk gSA bl otg ls leku Data dks vyx&vyx Application Software esa mlh fLFkfr esa Use fd;k tk ldrk gS] tcfd Data Access Library, Data Source dks XML Format esa Access o Manipulate dj ldsA blfy, ADO dks Modify djds bl yk;d cukuk Hkh t:jh Fkk fd og XML Data dks Handle dj ldsA D;ksafd ftl le; ADO.NET dks fodflr fd;k tk jgk Fkk] ml le; fofHkUu izdkj dh Web Services ds ek/;e ls tks Data fofHkUu izdkj ds Client Applications dks Provide fd;k tkrk Fkk] og Data XML Format esa gh gksrk FkkA blfy, ADO.NET dks Develop djus dk ,d dkj.k ;s Hkh Fkk fd fofHkUu izdkj ds Client Applications vyx&vyx ek/;eksa ls Generate gksus okys Data dks XML ds :i esa Defined ,d Universal Format esa Platform Independent rjhds ls Access o Manipulate dj ldsaA lkFk gh ADO, Disconnected Computing dks Hkh Support ugha djrk Fkk] tcfd Market dh Requirement dks vklkuh ls iwjk djus ds fy, ;s t:jh Fkk fd ADO dks Disconnected Computing ds fy, Hkh fodflr fd;k tk,A D;ksafd XML Support, Concurrency o Disconnected Architecture ;qDr ADO dks gh ADO.NET ds uke ls tkuk tkrk gSA tSlkfd ge tkurs gSa fd .NET Classes dks Namespaces esa Group fd;k tk ldrk gSA blfy, ADO.NET Related Functionality dh lHkh Classes dks System.Data Namespace ds vUrxZr j[kk x;k gSA lkFk gh vU; .NET Components dh rjg ADO.NET, .NET Framework ds vU; Namespaces tSls fd System.Web.UI.WebControls.Adapters.TableAdapter ;k System.Transaction ds lkFk Interaction dj ldrk gSA ADO.NET Architecture dks ewy :i ls nks Hkkxksa esa Divide fd;k tk ldrk gS] ftls Connected Database o Disconnected Database ds :i esa Identify fd;k tkrk gSA blfy, ADO.NET ls lEcaf/kr fofHkUu Classes dks Hkh Connected o Disconnected ds :i esa
  18. 18. 17 www.BccFalna.com ADO.NET with C# in Hindi nks Hkkxksa esa Divide fd;k tk ldrk gSA dsoy DataAdapter Type gh ,d viokn gS] tks Connected o Disconnected, nksuksa izdkj ds Mode esa leku izdkj ls dke djrk gSA Connected Objects Connected Part ,sls Object dks Represent djrk gS] tks Data Source ls Interact djrs le; Data Source o Frontend ds chp Connection Open j[krk gSA ;kuh ftl Object dks Data Source ls Data dks Access o Manipulate djus ds fy, ;s t:jh gksrk gS fd Frontend ds fy, Data Source ij Connection rc rd Open jgs] tc rd fd Frontend Client o Backend Data Source ds chp Data ysu&nsu ds fy, Perform gksus okyk Communication lekIr ugha gks tkrkA ADO.NET ds Connected Part ds vUrxZr eq[;r% fuEu eq[; Objects gksrs gSa% Connection Object ;s og Object gksrk gS] tks Frontend dk Backend Data Source ds lkFk Connection Establish djrk gSA bl ckr ij fuHkZj djrs gq, fd fdl izdkj ds Data Source ls Data dks Store/Retrieve djus ds fy, dkSulk .NET Data Provider Involved gS] og Specific .NET Data Provider gekjh fdlh Specified SQL Query ds vk/kkj ij Physical Database Connection ls Actual Data Retrieve djrk gSA OleDbConnection, SqlConnection, OracleConnection vkfn Connection Type Object ds mnkgj.k gSa] tks fd ,d Connected Object gksrk gSA tc Frontend fdlh Underlying Backend Database ls Connect gksrk gS] rks nksuksa ds chp ;s Connection Establish gksuk dkQh Time Consuming Task gksrk gSA D;ksafd nksuksa ds chp Connection Establish djus ds fy, Socket ;k Named PIPE ds :i esa ,d Physical Channel Establish gksrk gS vkSj Client o Server ds chp ,d Initialize Handshake gksus ds fy, Connection String Information Parse gksrk gS] ftldk Server }kjk Authentication fd;k tkrk gSA izk;ksfxd :i ls T;knkrj Applications Connection Establish djus ds fy, ,d ;k nks Unique Configurations dks Use djrs gSaA bldk eryc ;s gqvk fd Application ds Execution ds nkSjku dbZ Identical Connections ckj&ckj tYnh&tYnh Open o Close gksrs gSaA bl ckj&ckj Identical Connections ds Open o Close gksus dh izfØ;k dks de djus ds fy, gh ADO.NET ,d Optimization rduhd Use djrk gS] ftls Connection Pooling ds uke ls tkuk tkrk gSA Connection Pooling ,d ,slh izfØ;k gS] ftlesa Identical Connections dks dsoy ,d gh ckj Open fd;k tkrk gS vkSj Physical Connection dks gj Identical Connection ds fy, Open j[krs gq, Reuse dj fy;k tkrk gSA
  19. 19. 18 www.BccFalna.com ADO.NET with C# in Hindi ifj.kkeLo:i tc Hkh dHkh Connection dks Open djus dk Request feyrk gS] Application lcls igys ml Request dks Pool esa Existence ds fy, Check djrk gSA ;kuh ;fn Open gksus okys Connection ds Identical Connection dks ;fn igys Open fd;k tk pqdk gks] rks Pool ds :i esa og Connection igys ls Exist gksrk gSA bl fLFkfr esa u;k Connection Open ugha fd;k tkrk] cfYd ml igys ls Pool esa Exist Connection dks Reuse dj fy;k tkrk gSA bl izdkj ls gj Unique Connection String Configuration ds fy, ADO.NET ,d Pool (Stored Connection) Create djrk gS vkSj gj Identical Connection String Configuration ds fy, ml Pool esa Stored Connection dks gh Reuse djrk gSA Transaction Object dbZ ckj ,slh fLFkfr gksrh gS] tc gesa cgqr lkjs SQL Statements ds iwjs ,d Group dks Data Source ij ,d lkFk ,d Atomic Operation dh rjg Execute djuk gksrk gSA tgka ;k rks ml Statement Group ds lHkh Statements dk ,d lkFk Execution gksuk t:jh gksrk gS vFkok t:jh gksrk gS fd fdlh ,d Hkh Statement dk Execution ugha gksA bl izfØ;k dks lkekU;r% “All or Nothing” Operation dgk tkrk gSA mnkgj.k ds fy, tc ge Net Banking ds ek/;e ls fdlh ,d Bank A/c ls fdlh nwljs Bank A/c esa Payment Transfer djrs gSa] rks ,d ,d Bank A/c dk Balance de gksrk gS vkSj nwljs dk c< tkrk gSA ;kuh nksuksa dke ,d lkFk gh gksrs gSa vkSj ;fn gksrs gSa rks nksuksa gh dke gksrs gSa vU;Fkk dksbZ Hkh dke ugha gksrkA bl izfØ;k dks DBMS dh Hkk’kk esa lkekU;r% Transaction ds uke ls tkuk tkrk gSA OleDbTransaction, SqlTransaction, OracleTransaction vkfn Transaction Objects ds Example gSaA tcfd ADO.NET 2.0 gesa Distributed Transactions Perform djus dh lqfo/kk Hkh Provide djrk gSA lkFk gh ge System.Transaction Namespace ds Types dk iz;ksx djds Non-Database Transactions Hkh Perform dj ldrs gSaA DataAdapter Object ;s Object ADO.NET ds Disconnected o Connected Parts ds chp Gateway dh rjg dke djrk gSA ;s gekjs fy, Backend Data Source ds lkFk Connection Establish djrk gS vFkok bls dksbZ Established Connection Provide djus ij ;s ml Specified Connection ds ckjs esa fofHkUu izdkj dh tkudkfj;ka Provide djrk gS] ftudk iz;ksx Disconnected Object ds Data dks Identify djus o ml ij fdlh Specific Manner esa Act djus dh lqfo/kk Provide djrk gSA SqlDataAdapter, OracleDataAdapter, OleDbDataAdapter vkfn bl izdkj ds Objects ds mnkgj.k gSaA
  20. 20. 19 www.BccFalna.com ADO.NET with C# in Hindi Command Object ;s Object Underlying Data Source ij Execute fd, tkus okys Command (SQL Statement or Transaction) dks Represent djrk gSA ;s Command Object dksbZ Result Return dj Hkh ldrk gS vkSj ugha HkhA bu Command Objects dk iz;ksx Underlying Data Source ds Data dks Access, Manipulate, Query, Update, Delete vkfn djus ds fy, fd;k tkrk gSA lkFk gh ;s Commands, Underlying Database ds Table Structure dks Manipulate djus ds fy, Hkh mi;ksx esa fy, tk ldrs gSaA SqlCommand, OracleCommand, OleDbCommand vkfn bl izdkj ds Objects ds mnkgj.k gSaA Parameter Object Command esa ;s {kerk gksuh pkfg, fd og Parameters Accept dj ldsA rkfd Command ds SQL Statement ;k Stored Procedure dks Dynamically Modify djrs gq, vyx&vyx rjg ds Result Generate fd, tk ldsaA ;s Parameters Input vFkok Output fdlh Hkh izdkj ds gks ldrs gSaA lkFk gh ;s Parameters fdlh Stored Procedure ls Return gksus okys eku dks Represent dj ldrs gSa vFkok fdlh SQL Query esa Pass fd, x, “?” Arguments gks ldrs gSa ;k fQj fdlh Dynamic Query ds Named Parameters gks ldrs gSaA OleDbParameter, SqlParameter, OracleParameter vkfn bl izdkj ds Objects ds mnkgj.k gSaA DataReader Object ;s Object Read-Only ;k Forward-Only Cursor ds leku gS tks gesa Database ds Data dks Readonly o Forward Only Mode esa cgqr gh Fast Speed ls Fetch djus dh lqfo/kk Provide djrk gSA Disconnected Objects orZeku le; ds Modern Distributed Applications dh Requirements dks Connected Applications vdsys vius Lrj ij iwjk ugha dj ldrsA gkykafd Disconnected Applications Hkh ADO.NET dk iz;ksx djrs gq, gh Develop fd, tkrs gSa] ysfdu bl Development dk Approach dkQh fHkUu gksrk gSA Disconnected Applications lkekU;r% ftruk nsj ls lEHko gks] mruk nsj ls Underlying Database ls Connection Establish djrs gSa vkSj ftruk tYnh gks lds] mruk tYnh Disconnect gksus dh dksf”k”k djrs gSaA bl Disconnected Fashion esa ADO.NET, Actual Data Connection dks fofHkUu Requests ds nkSjku Underlying Database Pool ls Retrieve djrk gS vkSj Retrieved Data dks Local
  21. 21. 20 www.BccFalna.com ADO.NET with C# in Hindi Cache esa Save djds j[k ysrk gSA ADO.NET ds fofHkUu Disconnected Objects ds ckjs esa ge fuEukuqlkj tku ldrs gSa% DataSet Object DataSet Object, Disconnected Mode ds ADO.NET Data Access dk Central Core ;kuh eq[; vk/kkj gksrk gSA DataSet dks ljy “kCnksa esa bl rjg ls le>k tk ldrk gS fd DataSet ,d izdkj ls gekjs Current Frontend Application ds fy, ,d Mini Relational Database Management System (RDBMS) Software dh rjg dke djrk gS vkSj Underlying Database dks iwjh rjg ls Local Computer dh Memory esa Represent djrk gSA blfy, ge DataSet dks Exactly mlh izdkj ls Access o Manipulate djrs gSa] tSls fd ge Actual Data Source dks Use dj jgs gksaA DataSet dks ge DataTables o DataRelations dk Logical Collection Hkh eku ldrs gSaA DataTable Object DataTable yxHkx Actual Database dh Table ds leku gksrk gS] tks fd Actual Database dh fdlh Table dk In-Memory Representation gksrk gSA ;s DataColumns o DataRows dk cuk gksrk gS] ftl ij Exactly mlh rjg ls fofHkUu izdkj ds Constraints Set fd, tk ldrs gSa] ftl izdkj ls Actual Database esa fdlh Table ij fofHkUu izdkj ds Constraints Set fd, tkrs gSaA ;s Object Data dks Rows o Columns ds :i esa Store djrk gS vkSj bl Object dks iwjh rjg ls XML Format esa Convert fd;k tk ldrk gS] tcfd XML Format esa Serialized Content ds vk/kkj ij fQj ls DataSet Object Hkh Define fd;k tk ldrk gSA blfy, tc fdlh DataSet ds ek/;e ls dsoy ,d gh Table ds Data dks Access djuk gks] rks DataSet Create djus ds LFkku ij DataTable Create djuk T;knk csgrj gksrk gS vkSj DataTable dk iz;ksx djuk u dsoy T;knk vklku gksrk gS cfYd bldh Performance Hkh rqyukRed :i ls T;knk csgrj gksrh gSA DataRow Object DataRow Object okLro esa DataTable Object dh ,d Property gS] tks fd DataColumnCollection Type dk Object gksrk gS vkSj DataTable Object esa Stored fofHkUu Records esa ls fdlh le; ij fdlh ,d Record dks Represent djrk gSA tSls&tSls DataTable Object esa u;k Data Fill gksrk tkrk gS] gj Record dks Represent djus ds fy, DataRowCollection esa ,d u;k DataRow Object Add gksrk tkrk gSA DataRow Object okLro esa fdlh Actual Database ds fdlh Table dh fdlh Row dks In- Memory Represent djrk gSA
  22. 22. 21 www.BccFalna.com ADO.NET with C# in Hindi DataColumn Object DataColumn Object Hkh okLro esa DataTable Object dh ,d Property gS] tks fd DataRowCollection Type dk Object gS vkSj fdlh Actual Database Table Structure dks Represent djrk gSA ;kuh DataRow Object okLro esa fdlh Actual Database ds fdlh Table ds fdlh Column dks In-Memory Represent djrk gSA DataView Object DataView Object fdlh Actual Database ds fdlh View Object dk In-Memory Logical Representation gksrk gSA ;s Object gesa fdlh DataTable ij In-Memory View Create djus dh lqfo/kk nsrk gSA Actual View dh rjg gh ;s DataView Hkh viuh Filter Property esa Specified Condition ds vk/kkj ij orZeku esa Memory esa Exist Data dk Logical View Create djrk gSA DataTable ds Data ds Subset ;kuh View ds Data dks Sorted Form esa Handle djus ds fy, ge DataView Object ds lkFk Sort Property dk Hkh iz;ksx dj ldrs gSaA Constraints Object Constraints Object Hkh okLro esa DataTable Object dh ,d Property gS] tks fd ConstraintsCollection Type dk Object gSA ;s Object gesa ForeignKeyConstraint ;k UniqueConstraint Object Create djus dh lqfo/kk nsrk gS] ftUgsa ge fdlh Specific Condition ds vk/kkj ij DataTable ds fofHkUu Columns ds lkFk Associate dj ldrs gSa] rkfd DataTable esa Store gksus okyk Data bu Constraints dks Satisfy fd, fcuk fdlh u, Data dks Store u gksus nsA ForeignKeyConstraint o UniqueConstraint ;s nksuksa Constraint Collections, Logically Actual Database ds Foreign Key o Unique Key ds leku gksrs gSaA DataRelation Object DataSet Object fdlh Actual Database ds leku cgqr lkjh In-Memory Tables dks Logically Represent djrk gS] ftlesa cgqr lkjh Interrelated Tables gks ldrh gSA DataRelation Object bUgha fofHkUu Interrelated Tables ds chp dh Relationship dks Represent djrk gSA lkFk gh fofHkUu Related Tables ds Data dks Validate djrs gq, fofHkUu DataTables ds chp dh Parent-Child Relationship dks Hkh Represent djrk gSA bl Object dks ge Actual Database dh Foreign Key ds Equivalent eku ldrs gSa] tks fd nks Tables ds chp dh Relationship dks ,d uke ds ek/;e ls Represent djrk gSA ForeignKeyConstraint o DataRelation ds chp eq[; vUrj ;gh gS fd DataRelation Object gesa Data Validation dh lqfo/kk Provide djus ds lkFk gh ,d ,slk Convenient Mechanism Provide djrk gS] ftldk iz;ksx djds ge DataSet Object esa Parent o Child Rows dks Browse dj ldrs gSaA
  23. 23. 22 www.BccFalna.com ADO.NET with C# in Hindi bl izdkj ls ge ADO.NET ds Connected o Disconnected nksuksa Parts ds vkilh Interaction dks fuEu fp= }kjk T;knk csgrj rjhds ls Represent dj ldrs gSa vkSj le> ldrs gSa fd ADO.NET ds mijksDrkuqlkj Discussed fofHkUu Objects vkil esa fdl izdkj ls Interaction djrs gq, Frontend o Backend ds chp Communication Provide djrs gSa% ADO Architecture ds vUrxZr Data Source ls Returned Data dks Hold djus dk tks dke Recordset Object djrk Fkk] ogh dke ADO.NET Architecture esa DataSet djrk gSA fQj Hkh nksuksa ds chp ,d cgqr gh egRoiw.kZ vUrj gksrk gSA Recordset Object, Database ls Communicate djus ds fy, Hkh ftEesnkj gksrk Fkk] ogha DataSet Object fdlh Hkh rjg ls fdlh Database ls Directly Communication LFkkfir ugha dj ldrkA cfYd Database ls Connection Establish djus ds fy, ADO.NET Architecture, DataAdapter uke ds Gateway Object dks Use djrk gS tks fd Connected o Disconnected Modes dks vkil esa Communicate djokrk gSA pwafd Connected Objects, Directly Underlying Database ds lkFk Communication djrs gSa] blfy, Connected Objects dks lkekU;r% Database Specific Codes Implement djus gksrs gSa vkSj lHkh Connected Objects dks .NET Data Providers ds :i esa Identify ;k Refer fd;k tkrk gSA tcfd Disconnected Objects, Underlying Database ls fcYdqy Lora= o vyx gksrs gSa] vr% bu Disconnected Objects dks fofHkUu izdkj ds vyx&vyx Databases ds fy, leku :i ls Use fd;k tk ldrk gSA ;kuh ;fn geus MySql Database dks Use djrs gq, Disconnected rjhds ls viuk Application Design fd;k gks] rks ge tc pkgsa rc MySql ds LFkku ij Underlying Database ds :i esa SQL Server ;k Oracle dks Use dj ldrs gSa] tcfd gesa gekjs Disconnected Design esa fdlh Hkh rjg dk dksbZ Modification djus dh t:jr ugha gksxhA .NET Data Providers ADO.NET Connected Objects dks Underlying Database ds fy, ,d Specific Implementation ds :i esa Split djrk gSA vU; “kCnksa esa dgsa rks ;fn ge Frontend dks Microsoft SQL Server Database ds lkFk Connect djuk pkgrs gSa] rks gesa ADO.NET ds
  24. 24. 23 www.BccFalna.com ADO.NET with C# in Hindi SqlConnection Class dks Use djuk gksrk gSA ;kuh SQL Server Specific lHkh Classes System.Data.SqlClient Namespace ds vUrxZr Exist gksrh gSaA blh rjg ls Oracle Database ls Connection LFkkfir djus ls lEcaf/kr lHkh Classes System.Data.OracleClient Namespace ds vUrxZr Exist gSa vkSj ;fn ge Frontend dks Oracle Database ds lkFk Connect djuk pkgsa] rks gesa OracleConnection Class dks Use djuk gksrk gSA bl rjg ls gj Specific Database ds lkFk Frontend dks Connect djus ds fy, gesa vyx izdkj ds .NET Data Provider dks Use djuk gksrk gS vkSj gj rjg dk .NET Data Provider ,d vyx o Unique izdkj ds Namespace ds :i esa ADO.NET Implementation ds :i esa Exist gSA bl Implementation System dks ge fuEu fp= }kjk csgrj rjhds ls Represent dj ldrs gSa% orZeku le; esa ge dbZ izdkj ds Databases dks Use dj ldrs gSa] ftuesa ls File Based Database o Server Based Database orZeku le; esa dkQh Popular gSaA File Based Database dks tgka Manage o Deploy djuk dkQh vklku gksrk gS ogha Server Based Database T;knk Stable o Concurrent rjhds ls T;knk User Requests dks Handle djus esa l{ke gksrs gSaA gkykafd Microsoft SQL Server 2005 o ckn ds Server Based Databases dks File Based Database dh rjg Communicate fd;k tk ldrk gSA pwafd orZeku le; esa cgqr lkjs izdkj ds File Based o Server Based DBMS Software Available gSa] blfy, t:jh gS fd ADO.NET fofHkUu izdkj ds Data Sources dks Handle djrs gq, Frontend ds lkFk Backend dk Communication djok ldsA ;kuh fofHkUu izdkj ds Data Sources dks Support dj ldsA pwafd fofHkUu izdkj ds Data Sources dh viuh vyx rjg dh fo”ks’krk,sa gksrh gSa] vr% ADO.NET ,d Specific Type dk Provider Model Support djrk gS] ftlds vUrxZr fdlh Particular Data Source ds fy, Specify fd, x, ADO.NET Provider dks fdlh Specific Namespace ds vUrxZr Classes ds lewg ds :i esa Define fd;k tkrk gSA vU; “kCnksa esa dgsa rks fdlh Specific Data Source dks .NET Frontend ds lkFk Use djus ds fy, mldk dksbZ Specific Data Provider gksuk t:jh gksrk gSA gkykafd OleDb o ODBC dks fdlh Hkh OleDb ;k ODBC Compliant Database ds lkFk dke djus ds fy, Design fd;k
  25. 25. 24 www.BccFalna.com ADO.NET with C# in Hindi x;k FkkA ysfdu budk Specific Implementation Hkh fdlh uk fdlh Specific .NET Data Provider esa gh Exist gksrk gSA tSls% ;kuh tSlkfd ge mijksDr fp= }kjk le> ldrs gSa fd lHkh izdkj ds Databases dks Frontend ds lkFk Interact djokus ds fy, ,d .NET Data Provider dh t:jr gksrh gS vkSj fofHkUu izdkj ds Databases ds fy, vyx&vyx izdkj ds .NET Data Providers dks ADO.NET Framework esa Namespaces ds :i esa Implement fd;k x;k gS] ftuds ek/;e ls fdlh Specific Database esa Stored Data dks Frontend ds ek/;e ls Implement fd;k tkrk gSA fofHkUu izdkj ds Common Data Providers ds ckjs esa ge fuEukuqlkj le> ldrs gSa% Data Source Name Provider Namespace Microsoft SQL Server 7.0 and above System.Data.SqlClient Oracle 8.1.6 and above System.Data.OracleClient SqlXml support in SQL Server System.Data.SqlXml Any ODBC data source System.Data.ODBC Any OleDb data source System.Data.OleDb ;gka /;ku nsus okyh ckr ;s gS fd Microsoft SQL Server 7.0 o ckn ds Versions rFkk Oracle 8.1.6 o ckn ds Versions dks OleDb o ODBC Data Providers ds ek/;e ls Hkh Access fd;k tk ldrk gSA blds vykok bUgsa buds Specific Data Providers tSls fd System.Data.SqlClient o System.Data.OracleClient ds ek/;e ls Hkh Access fd;k tk ldrk gSA tc ge fdlh Database ls Connect gksus ds fy, mlls lEcaf/kr Specific Data Provider dks Use djrs gSa] rks gesa OleDb ;k ODBC Data Providers dh rqyuk esa T;knk csgrj Performance izkIr gksrh gSA D;ksafd Specialized Data Providers T;knk csgrj Database Specific Functionalities ls ;qDr gksrs gSaA
  26. 26. 25 www.BccFalna.com ADO.NET with C# in Hindi lkFk gh Specialized Data Providers gesa Database Specific Data Types ds lkFk dke djus dh lqfo/kk Provide djrs gSaA ftldh otg ls Boxing/Unboxing Perform ugha gksrk vkSj Database dh Performance T;knk csgrj jgrh gSA ysfdu tc ge Non-Specialized Data Providers tSls fd OleDb ;k ODBC Use djrs gSa] rc lHkh Data Sources, Common Minimum Base Functionality gh Provide djrs gSaA ;s Data Providers Use djus ij Performance rks izHkkfor gksrh gh gS lkFk gh dbZ vU; izdkj ds Issues Hkh Resolve djus iMrs gSaA blfy, tgka rd lEHko gks] ADO.Net ds ek/;e ls fdlh Specific Data Provider dk iz;ksx djrs gq, gh Specific Data Source dks Access o Manipulate djuk pkfg, rFkk ODBC o OleDb dk iz;ksx tgka rd lEHko gks] ugha djuk pkfg,A ;kuh ;fn Backend Data Source MS SQL Server gks] rks gesa”kk System.Data.SqlClient.SqlConnection Type dk Object System.Data.IDbConnection Interface dks Implement djuk pkfg, vkSj System.Data.Providerbase.DbConnectionBase ls Inherit djuk pkfg,A D;ksafd ,slk djrs gq, ge Runtime Cast Errors ls cp ldrs gSaA gkykafd bl Approach dk ,d uqdlku ;s gS fd ge ftl Backend Database dks Use dj jgs gSa] mls dHkh Hkh Change ugha dj ldrsA tcfd Qk;nk ;s gS fd OleDb ;k ODBC Use djus ij gksus okyk Performance Loss ugha gksrkA blds foijhr ;fn ge Database Independent Code fy[kuk pkgrs gSa] rks gesa OleDb ;k ODBC Data Providers Use djus iMrs gSa] ftlls ge vius Backend Database dks viuh t:jr ds vuqlkj dHkh Hkh Change dj ldrs gSa] tcfd ,slk djus ij gekjs Database dh Performance ij foijhr izHkko iMrk gSA blds vykok ge Base Classes o Interfaces dk iz;ksx djrs gq, Hkh Frontend ds lkFk Backend dks Use dj ldrs gSaA tgka ADO.NET, Most Common rjhds ls Use gksus okys Objects ds fy, Standard Interfaces o Base Classes Provide djrk gSA blfy, System.Data.SqlClient.SqlConnection Object dks System.Data.IDbConnection Interface dks Implement djuk gksrk gS rFkk System.Data.Providerbase.DbConnectionBase dks Inherit djuk gksrk gSA bu Base Interface }kjk Represented Data Types ;k Implement fd, x, Interface ds lkFk izfØ;k djrs gq, ge Runtime Cast Errors dks Avoid dj ldrs gSaA bl Approach dk Disadvantage ;s gS fd gesa gesa”kk Common Minimum Base Functionality ds lkFk Stick jguk t:jh gksrk gS] gkykafd ,slk djus ij Hkh gekjs Database Interaction ds Performance ij fdlh rjg dk izHkko ugha iMrk] tks fd OleDb ;k ODBC dks Use djus ij iMrk gSA ge le> ldrs gSa fd mijksDrkuqlkj Discuss fd;k x;k dksbZ Hkh rjhdk Perfect ugha gSA blfy, ADO.NET gesa ,d vkSj vf/kd mi;qDr Coding rjhdk Provide djrk gSA bl rjhds ds vUrxZr ADO.NET gesa ,d Provider Factory Provide djrk gS] ftlesa Available Providers dks
  27. 27. 26 www.BccFalna.com ADO.NET with C# in Hindi String Variable ds :i esa ml fLFkfr esa Instantiate fd;k tk ldrk gS] tcfd gesa Correct Provider Name dh tkudkjh gksA bl rjhds dks ProviderBase Model ds uke ls Hkh tkuk tkrk gSA Using ProviderBase Model ;s Model Performance o Database Independency, nksuksa ds fy, gh dkQh mi;ksxh lkfcr gksrk gSA D;ksafd lkekU;r% fdlh Hkh Windows Operating System Based Computer ij ,d ls T;knk rjg ds Data Providers Installed gksrs gSaA ftldh tkudkjh izkIr djus ds fy, ge .NET Framework ds Machine.Config uke dh File ds DbProviderFactories uke ds Section dks mi;ksx esa ys ldrs gSaA bl Section esa ge fofHkUu izdkj ds Data Providers dks Define dj ldrs gSa] ftUgsa ProviderBase Model dk iz;ksx djrs gq, Access fd;k tk ldrk gSA Machine.Config File dk DbProviderFactories Section dqN fuEukuqlkj gks ldrk gS% ;s File lkekU;r% C: => Windows => Microsoft.Net uke ds Folder esa Exist fofHkUu .NET Frameworks esa Exist gksrh gSA ge gekjs Computer System esa Exist fofHkUu Data Providers dks fuEukuqlkj Program Code ds ek/;e ls vklkuh ls Enumerate dj ldrs gSa] ftlds fy, gesa mijksDrkuqlkj Machine.Config File dks Manually Open djus dh t:jr ugha jgrh% //C# Code using System; using System.Data.Common; using System.Data; namespace ConsoleApplication2 { class Program { static void Main(string[] args)
  28. 28. 27 www.BccFalna.com ADO.NET with C# in Hindi { DataTable factoryClassesTable = DbProviderFactories.GetFactoryClasses(); foreach (DataRow factoryClass in factoryClassesTable.Rows) { Console.WriteLine("Name:" + factoryClass["Name"]); Console.WriteLine("Description:" + factoryClass["Description"]); Console.WriteLine("Invariant Name:" + factoryClass["InvariantName"]); Console.WriteLine("n"); } } } } 'VB Code Imports System Imports System.Data.Common Module Module1 Sub Main() Dim factoryClassesTable As DataTable = DbProviderFactories.GetFactoryClasses() Dim factoryClass As DataRow For Each factoryClass In factoryClassesTable.Rows Console.WriteLine("Name:" & factoryClass("Name")) Console.WriteLine("Description:" & factoryClass("Description")) Console.WriteLine("Invariant Name:" & factoryClass("InvariantName")) Console.WriteLine("") Next End Sub End Module tc ge mijksDr C# ;k VB.NET Console Applications dks Compile djds Run djrs gSa] rks gesa fuEukuqlkj Output izkIr gksxk gS] ftlesa gesa gekjs Computer System ij miyC/k fofHkUu Data Providers dh tkudkjh izkIr gks tkrh gS fd gekjs Current Computer System ij dkSu&dkSu ls Data Providers Exist gSa %
  29. 29. 28 www.BccFalna.com ADO.NET with C# in Hindi ;fn ge bu Providers dks vius C# ;k VB.NET Program esa Use djuk pkgsa] rks fuEukuqlkj dj ldrs gSa% //C# Code //Select SQL Client factory - Can change to use any provider later DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient"); //Create Connection from the factory SqlConnection testConnection = (SqlConnection)factory.CreateConnection(); testConnection.ConnectionString = "..."; //Specify connection string – See Chapter 4 testConnection.Open(); //Create Command from the factory SqlCommand testCommand = (SqlCommand)factory.CreateCommand(); //Execute a command from the connection testCommand.Connection = testConnection; testCommand.CommandText = "..."; SqlDataReader reader = testCommand.ExecuteReader(); while (reader.Read())
  30. 30. 29 www.BccFalna.com ADO.NET with C# in Hindi { Console.WriteLine(reader.GetValue(0)); } 'VB Code 'Select SQL Client factory - Can change to use any provider later Dim factory As DbProviderFactory=DbProviderFactories.GetFactory("System.Data.SqlClient") 'Create Connection from the factory Dim testConnection As SqlConnection = factory.CreateConnection() testConnection.ConnectionString = "..." ' Specify connection string testConnection.Open() 'Create Command from the factory Dim testCommand As SqlCommand = factory.CreateCommand() 'Execute a command from the connection testCommand.Connection = testConnection testCommand.CommandText = "..." Dim reader As SqlDataReader = testCommand.ExecuteReader() While reader.Read() Console.WriteLine(reader.GetValue(0)) End While mijksDr Code }kjk ge ,d eq[; ckr ;s le> ldrs gSa fd ProviderBase Model gesa SqlConnection o SqlCommand tSls Strongly Typed Provider Specific Objects dks Retrieve djus dh lqfo/kk Provide djrk gSA tcfd Application User dks bl ckr dh dksbZ tkudkjh ugha gksrh fd og fdl Provider ds ek/;e ls Backend Database ls Communication dj jgk gSA ;kuh ;fn ge pkgsa rks GUI Form ij ,d ComboBox Create djds mlesa fofHkUu izdkj ds Providers dks Display dj ldrs gSa] tgka User Lo;a viuh bPNkuqlkj ftl fdlh Hkh Provider dks pkgs] mls Select dj ldrk gS vkSj ml Selected “Data Provider” String dks ge “System.Data.SqlClient” ds :i esa GetFactory Method esa Parameter dh rjg Pass djrs gq, Hkh Backend Database ls Connection Establish dj ldrs gSaA ge ,slk blfy, dj ldrs gSa D;ksafd DbProviderFactory Type dk Object gesa”kk ftu Objects dks Return djrk gS] os lHkh okLro esa fdlh .NET Data Provider dh Base Classes ds fofHkUu Common Objects dks Represent djrs gSaA ;s lHkh Common Base Classes System.Data.Common uke ds Namespace esa Exist gksrs gSa] ftUgsa Third-Party .NET Data Provider Create djus ds fy, Inherit fd;k tk ldrk gSA
  31. 31. 30 www.BccFalna.com ADO.NET with C# in Hindi Third-Party Data Providers ADO.NET esa cgqr lkjh ,slh Base Classes o Interfaces Exist gSa] ftUgsa Derive o Implement djds fofHkUu Third-Parties viuh t:jr ds vuqlkj fofHkUu izdkj ds u, .NET Data Provider Create dj ldrs gSa vkSj viuh t:jr ds vuqlkj Connection, Command vkfn tSls Common :i ls dke vkus okys Objects dks Specific rjhds ls Implement dj ldrs gSaA DbDataAdapter Class blh izdkj dh ,d Class gS] ftlesa IdbDataAdapter Interface dks Implement fd;k x;k gSA vr% SqlDataAdapter tks fd System.Data.SqlClient esa Exist gksrk gS] DbDataAdapter ls Derived gS vkSj IdbDataAdapter Interface dks Implement djrk gSA System.Data.Common Namespace dh eq[; :i ls Notable Classes fuEukuqlkj gSa% DataAdapter Class bl Class ds Objects ADO.NET ds Connected o Disconnected Parts ds chp e/;LFk dk dke djrs gSaA ;s Objects DbCommand Objects ds :i esa Data Commands dks rFkk DbConnection Object ds :i esa Data Source Connection ds Hold djrs gSa tks fd DataSet o DataTable Objects dks Appropriate Data ls Fill djrs gSa lkFk gh Data Source dks Update djrs gSaA ;s Data Source, DbDataAdapter ds vykok fdlh Hkh izdkj dk gks ldrk gS] D;ksafd ;s dsoy Relational Data Source ds lkFk gh dke djrk gSA DbCommand Class bl Class ds Objects dk iz;ksx Data Source ij SQL Commands dks Execute djus ds fy, fd;k tkrk gSA DbCommandBuilder Class bl Class ds Objects Command Object ds fy, INSERT, UPDATE o DELETE SQL Statements Create djrs gSa] ftUgsa Data Adapter }kjk Use fd;k tkrk gSA bl Type ds Objects dk iz;ksx dsoy fdlh Single Data Source Table ds lkFk gh fd;k tk ldrk gS vkSj dsoy mlh fLFkfr esa fd;k tk ldrk gS] tcfd SELECT SQL Statement Specify fd;k x;k gks rFkk Row Schema ds :i esa de ls de ,d Unique Column Return gksrk gSA DbConnection Class bl Class ds Objects Data Source ds lkFk Actual Connection Establish djus dk dke djrs gSaA
  32. 32. 31 www.BccFalna.com ADO.NET with C# in Hindi DbConnectionOption Class bl Class dk iz;ksx Provider Factory Classes }kjk fd;k tkrk gSA Provider Factory Classes }kjk bls Connection Create djus ds fy, Use fd;k tkrk gSA gkykafd bls fdlh Connection String dks Key-Value Pair ds :i esa Convert djus ds fy, Manually Hkh Use fd;k tk ldrk gSA bl Class esa dqN Properties o Methods gksrs gSa] tks fd fdlh Connection String Value dks Key-Value Pair o Integer rFkk Boolean ekuksa esa Convert djus esa l{ke gksrs gSaA lkFk gh Specified String esa fdlh Specific Key tSls fd “Data Source” vkfn dks Check djus dk dke Hkh dj ldrs gSaA DbConnectionStringBuilder Class ;s Class dksbZ Connection String Create djus okyh Base Class gS vkSj bldk iz;ksx Data Provider Factory ds lkFk djrs gq, fdlh Configuration File ls fdlh Connection String Create, Edit ;k Read djus rFkk Connection String dks Configuration File esa Save djus ds fy, fd;k tk ldrk gSA DbDataAdapter Class ;s ,d Abstract Helper Class gS] ftldk iz;ksx IDbDataAdapter Interface ds lkFk fd;k tkrk gSA DbDataAdapter Class dks DataAdapter Class ls Derive fd;k x;k gS vkSj bldk iz;ksx fdlh Relational Database ds fy, Data Adapter Create djus ds fy, fd;k tkrk gSA ,slk Data Adapter Create djus ds fy, ,d ,slh Class Create dh tkrh gS] ftlesa DbDataAdapter Class dks Inherit rFkk IdbDataAdapter Interface dks Implement fd;k x;k gksrk gSA DbDataReader Class ;s Class fdlh Data Source ls Return gksus okys Forward-Only Row Stream dks Read djrk gS] tgka ,d le; esa ,d ckj esa dsoy ,d gh Row (Record) Access gks ldrk gSA tc ge DbDataReader Class dk iz;ksx djrs gq, Rows dh Reading djrs gSa] rc ml nkSjku Connection dk Open jguk t:jh gksrk gS D;ksafd Request Perform gksus ij bu Rows dks Directly Data Source ls Read fd;k tkrk gSA DbDataRecord Class ;s Class IDataRecord o ICustomTypeDescriptor Interface dks Implement djrk gSA bl otg ls ;s DbEnumerator Class ds fy, Data-Binding Support Provide djrk gSA lkekU;r% bl Class dks ASP.NET Pages esa DataBinder.Eval Method ds LFkku ij Data-Binding djus ds fy, Use fd;k tkrk gS] tks fd Reflection dk iz;ksx djus ds dkj.k Performance dks izHkkfor djrk gSA
  33. 33. 32 www.BccFalna.com ADO.NET with C# in Hindi DbException Class ;s ,d Generic Exception Class gS] ftldk iz;ksx Data-Related Exceptions Throw djus ds fy, fd;k tkrk gSA ;s ,d Abstract Class gS tks fd ExternalException Class ls Inherited gSA DbParameter Class bl Class dk iz;ksx gekjs SQL Command ds ek/;e ls Dynamic Queries Create djus ds fy, Parameters Pass djus gsrq fd;k tkrk gS] rkfd t:jr ds vuqlkj vyx&vyx Parameters Pass djds Command }kjk Database ij Fire gksus okyh SQL Queries dks Modify djrs gq, vyx&vyx izdkj ds Results izkIr fd, tk ldsaA DbProviderConfigurationHandler Class bl Class dk iz;ksx DbProviderFactory Class dks Application ds Configuration File esa Specified Values ds vk/kkj ij Configure djus ds fy, fd;k tkrk gSA DbProviderFactory Class bl Class dk iz;ksx fofHkUu izdkj ds Input ds fy, Provider-Specific Data-Aware Classes Create djus ds fy, fd;k tkrk gSA DbTransaction Class ;s ,d Generic Transaction Class gS] ftldk iz;ksx SQL Statements dks “All or Nothing” Transaction ds :i esa Encapsulate djus ds fy, fd;k tkrk gSA lkekU;r% bldk iz;ksx Connection Object ds lkFk fd;k tkrk gSA System.Data.Design Namespace ADO.NET Namespace dk ;s lcls NksVk Namespace gS] ftlesa Code o Parameters ds lkFk os Classes Exist gSa] ftudk iz;ksx DataSet Object Create djus ds fy, fd;k tkrk gSA bu Classes dks lkekU;r% ADO.NET }kjk Internally Use fd;k tkrk gS] ftUgsa ge Visual Studio esa DataAdapter Object ds ek/;e ls Created DataSet Object ds :i esa ns[k ldrs gSaA
  34. 34. 33 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET Object Model
  35. 35. 34 www.BccFalna.com ADO.NET with C# in Hindi ADO.NET – Object Model ADO.NET, .NET Framework ds vUrxZr System.Data Namespace ds :i esa Exist gSA tcfd .NET Framework ds vU; Namespaces tSls fd System.Windows.Forms, System.Xml, System.Web o vU; Namespaces, ADO.NET dh Classes ds lkFk Communication djrs gq, fofHkUu izdkj dh Data Related Accessing o Manipulation Requirements dks iwjk djrs gSaA BindingSource uke dh Class, System.Windows.Forms uke ds Namespace esa Exist blh izdkj dh ,d Class gS] ftldk iz;ksx Data-Binding Purpose dks iwjk djus ds fy, Data- Source dks Encapsulate djus gsrq fd;k tkrk gSA ADO.NET esa Defined Drag and Drop Operation, Data Driven Application Create djus dk ,d Quick o Easy rjhdk gS] tgka ge Data Source ls Bound Controls dks Drag and Drop rduhd dk iz;ksx djrs gq, cMh gh vklkuh ls Form ij Place dj ldrs gSa vkSj cMh gh rsth ls Data Driven, Working Application Form Design dj ldrs gSaA gkykafd tc ge Enterprise Level ds Data Driven Application Software Develop dj jgs gksrs gSa] rc ;s Drag and Drop rduhd gekjs fy, dqN T;knk mi;ksxh ugha gksrhA ml fLFkfr esa Manual Codes fy[kuk gh gekjs fy, lcls mi;qDr o csgrj Option jgrk gSA vr% ADO.NET ds Internal Architecture dks csgrj rjhds ls le>uk gekjs fy, cgqr t:jh gksrk gS] rkfd ge Enterprise Level ds Data Driven Application dks Develop djrs le; vius Application dks T;knk csgrj rjhds ls Control o Handle dj ldsaA fiNys Chapter esa geus ADO.NET ds ckjs esa ,d vkSj ckr le>h Fkh fd ADO.NET dk Connected Portion iwjh rjg ls Data Source Specific gksrk gSA tgka fdlh Particular Data Source ds fy, Define fd, x, Connected Portion dks ,d Combined Group ds :i esa .NET Data Provider ds uke ls Refer fd;k tkrk gSA lkekU;r% Data Providers ls lEcaf/kr fofHkUu Functionalities muds Lo;a ds uke ds Namespace ds ek/;e ls miyC/k gksrh gSa] tks fd System.Data Namespace ds vUnj Sub- Namespace ds :i esa Exist gksrs gSaA mnkgj.k ds fy, ;fn ge Oracle Database ls Connect djuk pkgrs gSa] rks Oracle Database ls Connection LFkkfir djus ls lEcaf/kr lHkh t:jh Functionalities System.Data.OracleClient uke ds Namespace esa Exist gksrh gSA blh rjg ls MS-SQL Server Database dks Use djus ls lEcaf/kr lHkh t:jh Functionalities System.Data.SqlClient uke ds Namespace esa Exist gksrh gSA gkykafd ;s ,d Convention gS] blfy, t:jh ugha gS fd lHkh Data Providers bl Convention dks iwjh rjg ls Follow djsaA okLro esa fofHkUu .NET Data Providers }kjk Supplied fofHkUu izdkj dh Classes o Interfaces dks fdlh Hkh Third-Party .NET Data Provider }kjk vklkuh ls Inherit o Implement fd;k tk ldrk gSA mnkgj.k ds fy, ge gekjh t:jr ds vuqlkj viuk Lo;a dk .Net Data Provider
  36. 36. 35 www.BccFalna.com ADO.NET with C# in Hindi Create dj ldrs gSa vkSj ,slk djus ds fy, gesa dsoy Appropriate Classes o Interfaces dks Inherit o Implement gh djuk gksrk gSA ADO.NET ,d Data Access Architecture gS] tks gesa fdlh Data Source ds lkFk Connection Establish djus] Data Source ij fdlh SQL Query dks Command ds ek/;e ls Execute djus] Command esa Specified SQL Queries dks Dynamic cukus gsrq muesa Parameters Pass djus o Command }kjk Fired SQL Queries ds dkj.k Generate gksus okys Results dks fQj ls Fetch djus dh lqfo/kk Provide djrk gSA DbConnection – To Establish Connection Data Source ds lkFk fdlh Hkh izdkj dh izfØ;k djus ds fy, lcls igys gekjs Frontend Application dks Backend Database ls Connection LFkkfir djuk gksrk gSA pwafd orZeku le; esa fofHkUu izdkj ds Data Sources (Oracle, SQL Server, MySql, etc…) Exist gSa vkSj ,d gh Computer System ij vyx&vyx Data Sources dks Install fd;k tk ldrk gS] blfy, gesa gekjs Frontend Application dk ftl Data Source ds lkFk Connection LFkkfir djuk gksrk gS] ml Data Source ds Name, User ID o Password dh t:jr gksrh gSA gkykafd fofHkUu izdkj ds Data Sources, fofHkUu izdkj ds Operations dks Support djrs gSaA ysfdu lHkh Data Sources esa dqN Functionalities iwjh rjg ls Common Hkh gksrh gSA tSls fd Connection Establish djuk] Data dks Database esa Insert, Update, Delete djuk o Database ds Connection dks Close djuk] vkfnA ;kuh fofHkUu izdkj ds Data Sources esa vkil esa dqN lekurk,sa gksrh gSa rks dqN vlekurk,sa Hkh gksrh gSaA blfy, ;s le>uk t:jh gS fd gj Data Source ds Connection Object dk ,d Individual Implementation gksrk gS] tks fd leku Base Class ls Inherit gksrk gS vkSj leku Interfaces dks Implement djrk gSA leku Base Class ls Inherit gksuk lHkh Data Sources dh leku Functionalities dks Represent djrk gS tcfd Create gksus okyh ubZ Class, esa Defined o Implemented u, Features, fofHkUu Data Sources dh fofHkUurkvksa dks Specify djus dk dke djrs gSaA ADO.NET dh Connection Class, DbConnection uke dh Base Class ls Inherit gksdj rFkk IDbConnection Interface dks Implement djds ;gh dke djrk gSA ;kuh Base Class dh Common Functionalities tSls fd Connection Open djuk, Connection Close djuk vkfn izkIr djrk gS tcfd Create gksus okyh ubZ Connection Class esa Data Source dh Specialties dks Handle djus ls lEcaf/kr Specific ckrksa dks bl Newly Create gksus okyh Connection Class esa IDbConnection Interface dks Implement djds Define fd;k tkrk gSA bl izdkj ls SqlConnection Class, tks fd System.Data.SqlClient.SqlConnection ds :i esa Exist gS] System.Data.Common.DbConnection ls Inherited gS vkSj System.Data.Common.DbConnection Class esa System.Data.IDbConnection Interface Implemented gSA
  37. 37. 36 www.BccFalna.com ADO.NET with C# in Hindi blh rjg ls OracleConnection Class, tks fd System.Data.SqlClient. OracleConnection ds :i esa Exist gS] System.Data.Common.DbConnection ls Inherited gS vkSj System.Data.Common.DbConnection Class esa System.Data.IDbConnection Interface Implemented gSA bl Hierarchy dks ge fuEu fp=kuqlkj T;knk ljy rjhds ls Represent dj ldrs gSa% ;kuh ADO.NET Architecture esa ,d Valid Connection Object ds :i esa Qualify djus ds fy, fdlh Hkh Class dks System.Data.Common.DbConnection Class dks Inherit djuk iMrk gSA tSlkfd mijksDr fp= esa ge ns[k ldrs gSa fd SqlConnection o OracleConnection uke dh nksuksa Connection Classes u dsoy IDbConnection Interface dks Implement dj jgs gSa] cfYd IDisposable Interface dks Hkh Implement dj jgs gSaA ,slk blfy, fd;k tk jgk gS D;ksafd gj Connection Object dqN Valuable Resources (Memory) Occupy djrk gS] ftls Dispose u djus ij og Resource fdlh vU; Object ds fy, Usable ugha jgrk] tc rd fd CLR }kjk Automated Garbage Collection Perform u
  38. 38. 37 www.BccFalna.com ADO.NET with C# in Hindi fd;k tk,A ysfdu IDisposable Interface dks Implement djus ij Create dh tk jgh Connection Class esa Dispose() Method dks Implement djuk t:jh gks tkrk gSA ifj.kkeLo:i gekjs Connection Class }kjk Occupied Resources dks Dispose djus dk Control gekjs ikl vk tkrk gS vkSj ge gekjh t:jr o bPNkuqlkj tc pkgsa rc Connection dks Dispose djrs gq, Connection }kjk Occupied Resources dks Free dj ldrs gSaA blh izdkj ls IDbConnection uke dk Interface fofHkUu Connection Objects ds chp ,d Common vk/kkj Establish djus ds fy, dqN Common Properties o Methods Specify djrk gS] ftls bl Interface dks Implement djus okyh Class esa Define djuk Compulsory gksrk gSA rkfd lHkh Connection Objects dk vk/kkj ,d leku gks vkSj lHkh Connection Objects, Valid Connection Object ds :i esa Qualify gks ldsaA ;kuh lHkh Connection Objects Frontend ls Connection Establish djus] Connection Close djus tSls Common Tasks dks Perform djus ds ekeys esa ,d leku gksaA blh otg ls fdlh Hkh .NET Data Provider dks Data Source ij Connection Establish djus ds fy, Use djrs le; ge Open() uke ds Method dks gh Use djrs gSa] Connect() ;k EstablishConnection() uke ds Method dks ughaA D;ksafd fiNys Paragraph esa Discussed rjhds ds vuqlkj Connection Class Define djus dh otg ls lHkh .NET Data Providers dks Connection Class ls lEcaf/kr leku Architecture dks Follow djuk iMrk gSA blfy, pkgs tks Hkh Data Source gks] ml Data Source ls lEcaf/kr Common Functionalities dks Perform djus ds fy, Common ukeksa dk gh iz;ksx djrs gq, Connection Class dks Define djuk t:jh gksrk gSA fiNys fp= ds vuqlkj /;ku nsus okyh ,d vkSj ckr ;s Hkh gS fd DbConnection Class dks System.ComponentModel.Component Class ls Derive fd;k x;k gSA ftldk eryc ;s gS fd ADO.Net Connection Object dks fdlh ,sls Environment esa Design Time esa Hosted fd;k tk ldrk gS] tks fd IContainer Interface dks Implement djrk gS D;ksafd fdlh Component dks fdlh ,sls Container ds vUnj Hosted fd;k tk ldrk gS] ftlesa IContainer Interface Implemented gSA Frontend Application dk Backend Database ds lkFk Connection Establish djuk lcls igyk dke gksrk gSA bl dke ds Perform gks tkus ds ckn gesa vxyk dke djuk gksrk gS ftlds vUrxZr ge ,d Command Execute djrs gSa tks fd ,d izdkj dk SQL Statement gksrkA Command dks gesa”kk fdlh Connection ij Execute fd;k tkrk gS vkSj D;ksafd ,d Command vius Underlying Data dks Change dj ldrk gS] blfy, ;s t:jh gksrk gS fd Command Object ds lkFk fdlh izdkj dk Transactional Semantics Associated gksA
  39. 39. 38 www.BccFalna.com ADO.NET with C# in Hindi DbCommand – To Execute Command ftl rjg ls ADO.NET Framework esa fofHkUu .NET Data Providers ds Implementations ds chp dqN Commonality gksrh gS] mlh rjg ls Command Object ij Hkh Commonality gksrh gSA ;kuh ftl rjg ls Connection Class dks System.Data.Common.DbConnection Class ls Inherit djuk gksrk gS] Bhd mlh rjg ls Command Class dks System.Data.Common.DbCommand Class ls Inherit djuk gksrk gS] tcfd Lo;a System.Data.Common.DbCommand Class esa IDbCommand Interface dks Implement fd;k x;k gSA vr% Microsoft SQL Server Specific Command Class, tks fd SqlClient Namespace esa Exist gS] DbCommand Class ls Inherited gSA blh rjg ls Oracle Server Specific Command Class, tks fd OracleClient Namespace esa Exist gS] Hkh DbCommand Class ls Inherited gSA blhfy, bu nksuksa gh Classes esa leku Behavior o Commonality Exist gSA pwafd fdlh Hkh Command dks Execute gksus ds fy, gesa”kk fdlh u fdlh Connection Object dh t:jr gksrh gS] bl dkj.k ls DbCommand Class esa Connection uke dh ,d Property Hkh Exist gS] ftlesa Specified Object dk DbConnection Type dk gksuk Hkh t:jh gksrk gSA blfy, D;ksafd SqlConnection Class, DbConnection Class ls Inherited gS vkSj SqlCommand Class, DbCommand Class ls Inherited gS] blfy, ge SqlConnection Object dks SqlCommand.Connection Property esa Specify dj ldrs gSaA blh rjg ls ;fn Command Object ds ek/;e ls fdlh Transaction dks Execute djuk gks] rks DbCommand Object esa Transaction uke dh Hkh ,d Property gksrh gS] tks fd DbTransaction Type dh Property gSA DbTransaction Class ,d Base Class gS] ftlesa IDbTransaction uke ds Interface dks Implement fd;k x;k gSA ftldh otg ls gesa fofHkUu .NET Data Providers ds Transaction Implementation esa Common Methods dks Define djuk gksrk gSA ifj.kkeLo:i gesa fofHkUu izdkj ds Data Sources ds fy, Common Methods o Properties dks Use djus dh lqfo/kk izkIr gks tkrh gSA blfy, ge OracleTransaction dks OracleCommand.Transaction Property esa Specify dj ldrs gSa] tks fd DbTransaction dks esa Inherit djrk gSA bl Implementation dks ge fuEu fp= }kjk T;knk csgrj rjhds ls le> ldrs gSa%
  40. 40. 39 www.BccFalna.com ADO.NET with C# in Hindi bl fp= esa ge tks ,d vkSj ckr Note dj ldrs gSa] og ;s gS fd DbConnection Class dh rjg gh DbCommand Class Hkh System.ComponentModel.Component Class ls Inherited gS] ftldh otg ls ge Visual Studio esa bl Command Object dks Visually ns[k ldrs gSaA lkekU;r% Commands dks Generic Fashion esa fy[kk tkrk gSA ;kuh Commands dks bl rjg ls fy[kk tkrk gS fd ge ,d gh Command Object dks vyx&vyx rjg dh t:jrksa dks iwjk djus ds fy, Reuse fd;k tk ldsA mnkgj.k ds fy, ;fn fdlh Command dks fdlh ,d Customer dh Information Retrieve djus ds fy, fy[kk x;k gS] rks vyx&vyx Parameters Pass djds mlh Command dks vyx&vyx Customers dh Information izkIr djus ds fy, Reuse fd;k tk lds] bl ckr dks /;ku esa j[krs gq, gh Commands Create fd, tkrs gSaA DbParameter – To Create Parameterized Commands Parameterized Queries dh viuh cgqr lkjh fo”ks’krk,sa gSa] ftlesa lcls eq[; fo”ks’krk ;gh gS fd ge ,d gh Command dks vyx&vyx Parameters Specify djrs gq, ,d gh SQL Statement dk iz;ksx vyx&vyx Record Retrieve djus ds fy, dj ldrs gSaA lkFk gh Parameterized Queries dk iz;ksx djus ij SQL Injection Attacks tSlh ijs”kkfu;ka Hkh iSnk
  41. 41. 40 www.BccFalna.com ADO.NET with C# in Hindi ugha gksrh] ftlls gekjk Database T;knk Secure jgrk gSA D;ksafd bl fLFkfr esa ge gekjs Parameter dks String Format esa ugha cfYd ,d Variable esa Stored String Format esa Specify djrs gSaA tSls% UPDATE Customers SET FirstName = 'Kuldeep' WHERE CustomerID = 1 blh Statement dks tc ge Parameterized Form esa fy[krs gSa] rks gekjk Statement dqN fuEukuqlkj gks tkrk gS% UPDATE Customers SET FirstName = @FirstName WHERE CustomerID = @CustID tc ge bl izdkj dh Query fy[krs gSa] rc gesa ;s lqfo/kk izkIr gks tkrh gS fd ge tc pkgsa rc Programmatically @FirstName o @CustID Variables dk eku Change djds blh SQL Query dks fdlh vU; Record dks Update djus ds fy, Use dj ldrs gSaA pwafd Command dks DbCommand Type ds Object }kjk Represent fd;k tkrk gS vkSj lHkh .NET Data Providers dks Parameterized Commands dh t:jr gks ldrh gS] blfy, Commonality dks Enforce djus ds fy, ;kuh lHkh .NET Data Providers }kjk leku izdkj ds dkeksa dks Perform djus gsrq leku uke dh Properties o Methods dks Define djus ds fy, Parameters uke dk ,d Property Provide fd;k tkrk gSA Parameters Property okLro esa DbParametersCollection Type dh ,d Property gS] tks fd DbParameter Class dk Connection ek= gSA bls ge fuEu fp= }kjk T;knk csgrj rjhds ls Represent dj ldrs gSa%
  42. 42. 41 www.BccFalna.com ADO.NET with C# in Hindi tSlkfd ge bl fp= esa ns[k ldrs gSa fd SqlCommand o OracleCommand nksuksa ds Parameters Property dks Double Arrow }kjk Represent fd;k x;k gS] tks fd bl ckr dk Indication gS fd ;s dksbZ Singular Object ugha cfYd ,d Collection gSA lkFk gh ge mijksDr fp= esa ;s Hkh ns[k ldrs gSa fd DbCommand.Parameters Property, DbParametersCollection dks Point dj jgk gS] tcfd SqlCommand.Parameters Property SqlParameterCollection dks Point dj jgk gS] tks fd cgqr lkjs SqlParameter dks Hold dj ldrk gSA blh rjg ls OracleCommand.Parameters Property, OracleParameterCollection Type ds Object dks Point djrk gS] tks fd OracleParameters dk ,d Collection gSA bl izdkj ls gj .NET Data Provider, tks fd Command Object dks Implement djrk gS] mlesa Parameters Property dk Exist gksuk t:jh gksrk gSA tcfd bl Parameters Property esa fdlh ,sls Type ds fdlh Object dks Hold djrk gS] ftls DbParametersCollection ls Inherit fd;k x;k gS vkSj tks DbParameter Class dk ,d Collection gSA tc fdlh Connection ij fdlh Command dks Execute dj fn;k tkrk gS] mlds ckn Data Source ls tks Result Return gksrk gS] mls fdlh Object esa Hold djus dh t:jr iMrh gS] rkfd Frontend Program esa ml Database ls Fetched Data dks Use fd;k tk ldsA
  43. 43. 42 www.BccFalna.com ADO.NET with C# in Hindi bl Data dks Hold djus ds fy, ge gekjk Lo;a dk Object Define dj ldrs gSa vFkok ;fn ge pkgsa rks .NET Framework ds DataSet Type ds Object dk Hkh iz;ksx dj ldrs gSa] tks fd gekjs Data dks Hold djus ds fy, ,d Disconnected Cache dh rjg O;ogkj djrk gSA DataSet – Holding Disconnected Data tSlkfd geus igys Chapter esa ns[kk Fkk fd ADO.NET dks ewy :i ls nks cMs Hkkxksa esa Divide fd;k x;k gS] ftlds vUrxZr fofHkUu Connected o Disconnected Type ds Objects dks Define fd;k x;k gSA Connection, Command, Transaction o Parameter Objects os Objects gSa] tks fd .NET Data Provider dks ifjHkkf’kr djrs gSaA ;kuh bUgh Objects ds Combination dks .NET Data Provider dgk tkrk gS vkSj bu Objects dks izfØ;k djus ds fy, gesa”kk Underlying Data Source ds lkFk Connected jguk t:jh gksrk gSA Commands dks ewy :i ls rhu Hkkxksa esa foHkkftr fd;k tk ldrk gS] ftUgsa Data Definition Language (DDL), Data Manipulation Language (DML) o Data Query Language (DQL) ds uke ls tkuk tkrk gSA DDL Commands dk iz;ksx djds fdlh Database ds Structure dks Define fd;k tkrk gSA DML Commands dk iz;ksx djds ge UPDATE, INSERT o DELETE Queries dks Underlying Data Source ij Execute djus dh lqfo/kk izkIr djrs gSaA tcfd DQL dk iz;ksx djds ge Database ij fofHkUu izdkj dh Queries dks Fire djrs gq, Database esa Stored Data dks Access djrs gSaA tc ,d ckj mijksDr rhuksa esa ls fdlh Hkh ,d izdkj dk Command Execute gks tkrk gS] rks vDlj bu Commands ds Execution ls Return gksus okyk Result Singular ugha gksrk ;kuh Executed Query ls ,d ls T;knk Results Generate gksrs gSaA Return gksus okyk Resultset ,d izdkj dk Tabular Formatted Data gksrk gS] ftlesa ,d ;k ,d ls vf/kd Rows (Records) Contained gks ldrs gSaA bl Resultset dks DataReader Object ds ek/;e ls Connected Fashion esa Hkh Read fd;k tk ldrk gSA tcfd Resultset dks Read djus dk vU; rjhdk ;s gS fd ge Returned Resultset ls fdlh Object dks Fill dj nsa] tks fd Underlying Data Source ls iwjh rjg ls Disconnected gksA pwafd Command ds Execute gksus ij Generate gksus okyk gekjk Data vius Underlying Database ls iwjh rjg ls Disconnected gksrk gS] blfy, bldk Implementation fdlh ,d Data Source ij vk/kkfjr ugha gksuk pkfg,A rkfd vyx&vyx izdkj ds Data Sources ls Generate gksus okys vyx&vyx izdkj ds Resultset dks bl Disconnected Object esa fcuk fdlh ijs”kkuh ds Hold fd;k tk ldsA vU; “kCnksa esa dgsa rks Generate gksus okys Resultset dks Hold djus okys Disconnected Data dk rc rd fdlh ,d Specific izdkj ds Underlying Data Source tSls fd MS SQL Server ;k Oracle ij vk/kkfjr ugha gksuk pkfg,] tc rd fd Connected o Disconnected Objects ds chp dksbZ Object Bridge dh rjg Exist gksA ;kuh ml Object dk Implementation, tks fd
  44. 44. 43 www.BccFalna.com ADO.NET with C# in Hindi Disconnected Data dks Hold dj jgk gS] mldk fdlh Particular Data Source (Oracle, MySQL, MSSQL Server, etc…) Specific ugha gksuk pkfg,A bl izdkj ls Implemented Connected o Disconnected Objects ds chp ds Bridge Object dks DataAdapter uke ls tkuk tkrk gSA tSlkfd geus igys Hkh dgk fd Command Execute gksus ds ckn Generate gksus okys Disconnected Data dks Hold djus ds fy, ge gekjk Lo;a dk Business Object Hkh Create dj ldrs gSa vFkok ;fn ge pkgsa rks .NET Framework ds igys ls Exist DataSet uke ds Object dks Hkh Use dj ldrs gSaA DataSet .NET Framework esa ,d igys ls Exist o Ready to Use Disconnected Cache Object gksrk gS] tks fd Command ds Execute gksus ds ckn Underlying Data Source ls Generate gksus okys Resultset dks Disconnected Form esa Hold djds j[krk gSA DataSet Object o mlls Associated fofHkUu Disconnected Objects ds Structure dks ge fuEukuqlkj Represent dj ldrs gSa% DataSet dks le>us dk lcls Best rjhdk ;s gS fd RDBMS dks DataSet ds leku gh ekuk tk,A ;kuh DataSet ,d izdkj ls fdlh RDBMS Software dk In-Memory Representation gh gksrk gSA bl Object dk eq[; mÌs”; oks djuk gS] tks RDBMS ugha dj ldrk] ;kuh ;s Object fdlh RDBMS ds Disconnected Form esa Memory esa Represent djrk gSA DataSet ftl izdkj ls fdlh RDBMS dk In-Memory Representation gksrk gS] Bhd mlh rjg ls DataTable fdlh RDBMS ds fdlh Table dk In-Memory Representation gksrk gSA
  45. 45. 44 www.BccFalna.com ADO.NET with C# in Hindi tcfd DataRelation Object fdlh RDBMS ds Foreign-Key Constraint dk In-Memory Representaion gksrk gSA blh rjg ls DataColumn fdlh RDBMS ds fdlh Table ds fdlh Column dk In-Memory Representation gksrk gS] tcfd DataRow fdlh RDBMS ds fdlh Table ds fdlh Row dk In-Memory Representation gksrk gSA bl izdkj ls DataSet Object esa Tables uke dh ,d Property ds :i esa DataTable Objects dk ,d Collection gksrk gS] tks fd DataTableCollection Type dk Object gksrk gSA tcfd DataSet Object esa Relations uke dh ,d Property ds :i esa DataRelation Objects dk ,d Collection gksrk gS] tks fd DataRelationCollection Type dk Object gksrk gSA blh rjg ls DataTable Object esa Columns uke dh ,d Property ds :i esa DataColumn Objects dk ,d Collection gksrk gS] tks fd DataColumnCollection Type dk Object gksrk gSA tcfd DataTable Object esa Rows uke dh ,d Property ds :i esa DataRow Objects dk ,d Collection gksrk gS] tks fd DataRowCollection Type dk Object gksrk gSA DataTable Object esa Constraint Hkh Defined gks ldrk gS] tks fd bl Object dh Constraints Property ds :i esa ConstraintCollection Type ds Objects dks Hold djrk gS tks fd ;k rks Constraint Type dk Object gksrk gS ;k fQj Constraint Type ls Inherit gksrk gSA tc ,d ckj gekjk Command Execute gks tkrk gS] ftls Execute djus ds ckn Underlying Data Source ls Generate gksus okys Resultset dks fdlh Disconnected Object esa Hold dj fn;k tkrk gS] mlds ckn ml Disconnected Data dks Read fd;k tkrk gSA DataReader and DataAdapter – To Fetch Resultset vc tcfd gekjs ikl ,d Object gS ftlesa Disconnected Data Hold gS vkSj fofHkUu izdkj ds Transactional o Parameterized Commands Execute gksus o Disconnected Data ls Connect gksus ds fy, fofHkUu izdkj ds Objects dk lewg miyC/k gS] vc gekjs ikl Underlying Data Source ls Data dks Fetch djus ds fy, nks rjhds gSa] ftudk iz;ksx fd;k tk ldrk gSA bu nksuksa rjhdksa esa eq[; vUrj bl ckr dk gS fd ;s nksuksa rjhds fdruh nsj rd Connection dks Open j[krs gSaA igys rjhds ds vUrxZr ge DataReader Object Use djrs gSa] ftls Generated Result dks Fetch djus ds fy, Open o Available Connection dh t:jr gksrh gSA ;s rjhdk Single User gksus dh fLFkfr esa T;knk Fast Speed ls dke djrk gSA ysfdu tc cgqr lkjs Users bl izdkj ls Access gks jgs Data dks Use djrs gSa] rc ;s rjhdk Connection Pooling dks dkQh izHkkfor djrk gSA nwljs rjhds ds vUrxZr ge DataAdapter Object dks Use djrs gSaA ;s Object FkksMk vyx rjhds ls dke djrk gS] ftlesa ;s Object Command dks Execute djus ds ckn Generate gksus okys
  46. 46. 45 www.BccFalna.com ADO.NET with C# in Hindi Resultset dks ,d DataSet ;k DataTable Object esa Fill djrk gS] tks fd ,d izdkj dk Disconnected Cache gksrk gSA tc ,d ckj ;s Object Command ds Fire gksus ds ckn Generate gksus okys lkjs Data dks fdlh Appropriate Object esa Fill dj nsrk gS] mlds ckn ;s vius vkidks Underlying Data Source ls Disconnect dj ysrk gSA ftlls ml Underlying Physical Connection dks fdlh vU; Object }kjk Reuse fd;k tk ldrk gSA DbDataReader – To Fetch Data in Connected Way dqN Commands Data Fetch djrs gSa] dqN Commands Data Manipulate djrs gSa tcfd dqN Commands nksuksa dke djrs gSaA bl otg ls Command dks Execute djus ds fy, DbCommand esa dbZ Methods gksrs gSaA mnkgj.k ds fy, DbCommand Object esa ExecuteNonQuery() uke dk ,d Method gksrk gS] tks Command ds Execute gksus ij Affect gksus okys dqy Rows dh la[;k Return djrk gSA blh izdkj ls DbCommand gesa ExecuteReader() uke dk ,d vkSj Method Provide djrk gS] ftls rc Use fd;k tkrk gS] tc ge fdlh Query ds Result dks Resultset dh rjg Fetch djuk pkgrs gSaA tcfd DbCommand dk ExecuteReader() Method ,d ,slk Object Return djrk gS] tks fd DbDataReader Class ls Inherited gksrk gSA tgka DbDataReader ,d Common Abstract Base Class gS vkSj fdlh Hkh Data Reader Class dks bls Inherit djuk t:jh gksrk gSA bl O;oLFkk dks ge fuEu fp= }kjk csgrj rjhds ls le> ldrs gSa%
  47. 47. 46 www.BccFalna.com ADO.NET with C# in Hindi tc gekjs ikl ,d DataReader Object gksrk gS] rc ge blds lkFk fofHkUu izdkj ds Methods dks Use dj ldrs gSa] Returned Resultset ds fofHkUu Records ij Iterate dj ldrs gSa vkSj Current Position ds Record ds fofHkUu Columns dh Values dks Read dj ldrs gSaA ;gka bl ckr dks /;ku j[kuk t:jh gS fd Data Reader ,d Read-Only ;k Forward-Only Object gksrk gS] tks mlh fLFkfr esa dke djrk gS] tcfd Underlying Physical Database Connection Open gksrk gSA DbDataAdapter – Bridge between Connected and Disconnected DataAdapter Object ,d Bridge Object gksrk gS] tks ADO.NET ds Disconnected Part o Connected Part ds chp Exist gksrk gS vkSj nksuksa ds chp ds Communication dk ek/;e curk gSA pwafd Data Adapter Object dk Actual Implementation iwjh rjg ls Underlying Data Source ij vk/kkfjr gksrk gS] blfy, ;fn Backend ds :i esa MSSQL Server dks Use fd;k tk jgk gks] rks ADO.NET ds Connected o Disconnected Parts dks Communicate djokus ds fy, SqlDataAdapter dh t:jr gksrh gSA tcfd ;fn Backend ds :i esa Oracle Server dks Use fd;k tk jgk gks] rks ADO.NET ds Connected o Disconnected Parts dks Communicate djokus ds fy, OracleDataAdapter dh t:jr gksrh gSA tcfd ;fn gesa ODBC ;k OleDb ds ek/;e ls Generic Access dh t:jr gks] rks gesa OdbcDataAdapter o OleDbDataAdapter tSls Generic Data Adapters ds ek/;e ls ADO.NET ds Connected o Disconnected Parts ds chp Communication LFkkfir djokuk iMrk gSA lkFk gh ADO.NET Object ds vU; Connected Parts dh rjg gh fofHkUu Data Adapters ds chp Commonality dks Enforce djus dh lqfo/kk DbDataAdapter Class ds ek/;e ls izkIr gksrh gS] ftlds ckjs esa ge fuEu fp= }kjk csgrj rjhds ls le> ldrs gSa%
  48. 48. 47 www.BccFalna.com ADO.NET with C# in Hindi tSlkfd ge mijksDr fp= esa ns[k ldrs gSa fd SqlCommand o OracleCommand uke dh nks Classes gSa vkSj nksuksa gh Classes DbCommand uke dh Class ls Inherited gSaA Data Adapter Class dks Normal rjhds ls dke djus ds fy, fofHkUu DbCommand tSls fd InsertCommand, UpdateCommand, DeleteCommand o SelectCommand dh t:jr gksrh gS tks fd Øe”k% INSERT, UPDATE, DELETE o SELECT uke ds SQL Operations dks Represent djrs gSaA DbDataAdapter uke dh Base Class, DbCommand Data Type dh pkj Properties ds :i esa bUgha pkjksa Commands dks Define djrk gSA SqlDataAdapter, OracleDataAdapter vkfn vU; Specific Data Adapters Hkh ADO.NET Connected Objects ds leku gh bUgha pkjksa Commands InsertCommand, UpdateCommand, DeleteCommand o SelectCommand dks pkj Properties ds :i esa Available djokrs gSa] tks fd Data Provider Specific Command Objects tSls fd SqlCommand o OracleCommand dks Value ds :i esa Accept djrs gSaA ADO.NET – Exception Handling fdlh Hkh Programming Language Architecture esa Exception Handling ,d cgqr gh egRoiw.kZ Part gksrk gSA blfy, .NET Architecture Hkh gesa ,d Exception Handling Mechanism Provide djrk gS] tks fd fofHkUu izdkj dh Error o Exception Conditions dks Handle djus dh lqfo/kk nsrk gSA C++ o Java dh rjg gh .NET Framework dh Programming Languages esa Hkh Exception Handling ds fy, try … catch Block rjhds dks gh Use fd;k x;k gSA ftlds vUrxZr tks
  49. 49. 48 www.BccFalna.com ADO.NET with C# in Hindi .NET Code fdlh Hkh rjg dk Error ;k Exception Trigger djus dk dkj.k cu ldrk gS] mls try Block esa Enclose fd;k tkrk gS] tcfd try Block esa Enclosed Code }kjk ftl fdlh Hkh rjg dh Errors Generate gks ldrh gSa] mu Errors dks Handle djus ls lEcaf/kr Error Handling Codes dks catch Block esa fy[kk tkrk gSA C# esa Exceptions o Errors dks Classes ds :i esa Implement fd;k x;k gSA blfy, ;fn try Block fdlh Hkh rjg dk Exception Trigger djrk gS] rks ml Exception dks og fdlh u fdlh Exception ;k Error Class ds Object ds :i esa gh Throw djrk gSA .NET Framework esa fofHkUu izdkj dh Database Related Errors o Exceptions dks Handle djus ls lEcaf/kr Classes dks fuEukuqlkj rjhds ls Implement fd;k x;k gS% tSlkfd ge mijksDr fp= }kjk le> ldrs gSa fd .NET Exception Classes dks ewy :i ls pkj Hkkxksa esa ckaVk x;k gS% Disconnected Stack Exceptions blds vUrxZr ftruh Hkh Classes Defined gSa] os lHkh System.Data.DataEexception uke dh Class ls Inherited gSa tks fd Disconnected Data Cache ls Generate gksus okys lHkh izdkj ds Exceptions dks Handle djus dk dke djrs gSaA Provider Specific Exceptions mijksDr fp= esa n”kkZ;h xbZ Exception Classes, Disconnected Object }kjk Generate gksus okys Exceptions dks Represent dj jgs gSaA tcfd Connected ;kuh Provider Stack ls lEcaf/kr Classes dks ge fuEu fp=kuqlkj n”kkZ ldrs gSa] tgka lHkh Exception Classes System.Data.Common.DbExceptoin Class ls Inherited gSa%
  50. 50. 49 www.BccFalna.com ADO.NET with C# in Hindi SqlType Specific Exception bl Group dh lHkh Exception Classes dks System.Data.SqlTypes.SqlTypeException uke dh Class ls Derive fd;k x;k gS vkSj tSlkfd ge uke ls gh le> ldrs gSa fd bl Group dh lHkh Classes iwjh rjg ls SQL Database }kjk Generate gksus okys Exceptions dks Handle djus dk dke djrs gSaA Other ADO.NET Exceptions bl Group dh lHkh Classes dks ewyr% System.Exception Class ls gh Derive fd;k x;k gS vkSj ;s Classes ADO.NET ds mu Exceptions dks Handle djus dk dke djrs gSa] ftUgsa mijksDrkuqlkj Specified rhuksa Categories }kjk Handle fd;k tkuk lEHko ugha gksrkA Summary of ADO.NET Data Model bl Chapter esa geus ADO.NET Data Model ds Objects ds Role dks Detail ls le>us dh dksf”k”k dhA fQj Hkh ADO.NET ds fofHkUu Components dks ,d Summary ds :i eas vxzkuqlkj Specify dj ldrs gSa] ftlls bl Model dks ;kn j[kuk vklku gks ldsA ADO.NET Data Model iwjh rjg ls System.Data Namespace ij vk/kkfjr gSA ge fcuk bl Namespace dks vius Application esa Use fd, gq, dksbZ Hkh Database Application Create ugha dj ldrsA ;gh Namespace fofHkUu izdkj ds Database Objects tSls fd Tables, Rows, Columns Constraints vkfn dks Represent djus ds fy, fofHkUu izdkj ds Types ;kuh Classes, Structures, Enumerations vkfn dks Define djrk gSA bl Namespace esa ewy :i ls fuEu Core Members dks Define fd;k x;k gksrk gS%

×