Page 1 :
CHAPTER, , , , pATA ACCESS WITH ADO.NET, a eee a eeeee, , ¢ INTRODUCTION TO ADO. NEF DATA OBJECTS, , \DO.NET is the next generation of ActiveX D., access that was built with Scalability, the statel, , ADO NE 1 provides an interface to all OLE DB-compliant data sources and lets youconnect, to. retrieve, manipulate, and update them. One can use it in a remote environment, using a, distributed application, or using disconnected data., In terms of ASP.NET development, ADO.NET provides the framework for accessing any, type of data for use with ASP.NET pages. This allows users to view or change information, stored in any kind of data warehouse, including databases, text files, and XML data stores., ADO.NET allows us to interact with different types of data sources and different types of, databases. ADO.NET provides a relatively common way to interact with data sources, but, comes in different sets of libraries for each way one can communicate to a data source., These libraries are called Data Providers and are usually named for the protocol or data, source type they allow you to interact with, , 1.1 ADO.NET Objects, The SqiConnection Object, lo interact with a database, one must have a connection to it. The connection helps identify, the database server, the database name, user name, password, and other parameters that, are required for connecting to the data base. A connection object is used by command, objects so they will know which database to execute the command on., The SqiCommand Object is, The process of interacting with a database means that one must specify the actions one, wants to occur. This is done with a command object. A command object is used to send, SQL statements to the database. A command object uses a connection object to figure out, which database to communicate with. One can use a command object alone, to execute a, Command directly, or assign a reference to a command object to an SqlDataAdapter, which, holds a set of commands that work on a group of data as described below,, , The SqiDataReader Object, , ata Objects (ADO). It's a model for data, essness of the Web, and XML at its core., , The data j llows to obtain the results of a SELECT statement from a command, reader object a e data returned from a data reader is a fast forward, Object For ‘ons, th, : performance reasons, ain't t, : é e can only pull the data from the stream in a, nly stream of data. This means that on ‘, , _ Sequential manner. s, : nner. Chaveanll, , , , , Scanned with CamScanner
Page 2 :
6.2 -Net Programm;, Ming, , The DataSet Object, , DataSet objects are in-memory representations 0 tables. On, . ¢ : j i e i, objects, which contain columns and rows, just like normal databave a , define relations between tables to create parent-child relationships. The DataSet 'S SPecifically, designed to help manage data in memory and to support disconnected a On da, when such a scenario make sense. The DataSet is an object that is use y all of the Data, , Providers, which is why it does not have a Data Provider specific prefix., , The SqiDataAdapter Object, , Sometimes the data one works with is primarily read-only @ d :, to the underlying data source. Some situations also call for caching data in memory to, , minimize the number of database calls for data that does not change. ng dete Pter, makes it easy to accomplish these things by helping to manage data. sg cig Cted, mode. The data adapter fills a DataSet object when reading the data and writes in a single, , batch when persisting changes back to the database. A data adapter contains a reference to, the connection object and opens and closes the connection automatically when reading, , from or writing to the database. Additionally, the data adapter contains command obje;, references for SELECT, INSERT, UPDATE, and DELETE operations on the data., 6.1.2 Difference between ADO and ADO.NET ;, * ADO used connected data usage, while ADO.net used disconne, environment., , + ADO used OLE DB to access data and is COM-based, while ADO.net, as the format for transmitting data to and from your database and web, , f data. They contain multiple Datatabj,, , nd rarely needs to make ¢, , , , , , , , , , , , + In ADO, Record set, is like a single table or query result, while in, Dataset, can contain multiple tables from any data source., , + In ADO, it is sometime problematic because firewall prohibits many, request, while in ADO.net there is no such problem because XML is, , firewall-proof, , , , , , ‘Visual Basic, Server Explorer allows to work with connections across, , , , visually. Server Explorer can be viewed by selecting View->S«, , , , Scanned with CamScanner
Page 4 :
-NetP!, , 6.4, e selecting the database is fin,, , i r”, One ae ., Select the option "select the database on the serve! f the connection is successfyy “a, , i ion. I, click on the Test Connection tab to test the “a an connection to the dug, ., message "Test Connection Succeeded” is displayee, is, : ands the connect, set, click OK and close the Data Link Properties. When ones fn that Nortelagi gat, ("+" sign), it displays the Tables, Views and Stored Broce Ple, , ilable in the dat, database. Expanding the Tables node will display all the tables avat'a tabase,, , , , , , , Be. eff, , , , , & Data Link Properties, , Provider Connection | Advanced | All |, , , , Specify the following to connect to SQL Server date:, , 1. Select or enter a server name: *, | x] Retresh |, , 2. Enter information to log on to the server:, © Use Windows NT Integrated security, , @ Use a specific user name and password:, , User name: [sa i, thay Password: — ae, , T Blank password I~ Allow savingpassword, , , , , , , , ‘Scanned with CamScanner
Page 5 :
Fr:, , with apo.Net, , es needs 10 generate the dataset that holds data fro, aW ong rGenerate DataSet from the main menu or right, , Nv ., cle oct generate DataSet menu. Doing that displays the, , se, ind ‘age pelowag, , , , 6.5, , m the data adapter. To do that, -Click SQLDataAdapterl object, generate Dataset dialogbox like, , aC, , ine, , , , Generate a dataset that includes the specified tables,, , choose 4 dataset;, , , , ( Existing ¥, , , , , , , , @ New: DataSet1, , Choose which table(s) to add to the dataset:, , , , , , Table1 (OleDbDataAdapter 1), , [¥ Add this dataset to the designer., , gs et Cancel | Help. |, , Fig. 6.3, , , , , , dialogbox is displayed, select the radio button with New option to create a new, Make sure Customers table is checked and click OK. Clicking OK ages a dataset,, 11 to the component tray and that's the dataset with which we will pe Nov, Grid from toolbox. Customers table is displayed in this data grid. Set fd ata, aSource property to DataSet! | and it's DataMember property to pees es, to fill the dataset with data from the data adapter. The following code does at:, , Scanned with CamScanner