An Introduction to ADO.Net .

Uploaded on:
Category: Travel / Places
Substance. What is ADO.Net?What happened to ADO?The ADO.Net object structureConnectingCommandingReaders and DataSets. What is ADO.Net?. The information access classes for the .Net frameworkDesigned for exceptionally effective information accessSupport for XML and detached record sets. What's more, the .Net structure?. A standard cross dialect interfaceEncapsulation of administrations, classes and information typesUses XML for information repre
Slide 1

An Introduction to ADO.Net Marmagna Desai .NET Seminar, Fall-2003

Slide 2

Contents What is ADO.Net? What happened to ADO? The ADO.Net question structure Connecting Commanding Readers and DataSets

Slide 3

What is ADO.Net? The information get to classes for the .Net structure Designed for exceedingly proficient information get to Support for XML and separated record sets

Slide 4

And the .Net system? A standard cross dialect interface Encapsulation of administrations, classes and information sorts Uses XML for information portrayal

Slide 5

Where does ADO sit? VB C# C++ Jscript … Common Language Specification ASP.Net Windows Forms Visual Studio .NET ADO.Net XML.Net Base Class Library Common Language Runtime (CLR) Windows COM+ Services

Slide 6

What happened to ADO? ADO still exists. ADO is firmly coupled to customer server structures Needs COM marshaling to pass information between levels Connections and locks are commonly persevered

Slide 7

ADO/ADO.Net Comparisons

Slide 8

ADO/ADO.Net Comparisons

Slide 9

.NET Data Providers SQL .NET Data Provider SQL SERVER OLE DB .NET Data Provider OLE DB Provider Client Other DB ODBC .NET Data Provider ODBC Driver Other DB

Slide 10

Data Provider Functionality Client .Net Data Provider Connection Command Rows DataReader DataSet DataAdapter database

Slide 11

ADO.Net protest show Fill DataAdapter DataSet Update Errors Collection UpdateCommand SelectCommand InsertCommand DeleteCommand Command Connection Parameters Data Source

Slide 12

Namespaces System.Data & System.Data.Common System.Data.SqlClient & System.Data.OleDB System.Data.SqlTypes System.XML & System.XML.Schema

Slide 13

Using Namespaces VB.Net Imports System.Data Imports System.Data.SqlClient Dim sqlAdp as SqlDataAdapter C# utilizing System.Data; utilizing System.Data.SqlClient; SqlDataAdapter sqlAdp= new SqlDataAdapter();

Slide 14

SQL Namespace Objects utilizing System.Data.SqlClient; SqlConnection SqlCommand SqlDataReader SqlDataAdapter SqlParameter SqlParameterCollection SqlError SqlErrorCollection SqlException SqlTransaction SqlDbType

Slide 15

Connecting to SQL utilizing System.Data.SqlClient; string sConnectionString = "Initial Catalog=Northwind; Data Source=localhost; Integrated Security=SSPI;"; SqlDataAdapter sqlAdp= new SqlDataAdapter(sConnectionString); sqlAdp.Close(); sqlAdp.Dispose();

Slide 16

Connection Pooling ADO.Net pools associations. When you close an association it is discharged once again into a pool. SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=northwind"; conn.Open();/Pool An is made. SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=pubs"; conn.Open();/Pool B is made in light of the fact that the association strings vary. SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=northwind"; conn.Open();/The association string matches pool A.

Slide 17

Getting information SqlCommand ExecuteReader ExecuteNonQuery ExecuteScalar ExecuteXMLReader SqlDataAdapter DataSet

Slide 18

Using the charge protest SqlCommand Multiple constructors New() New(cmdText) New(cmdText, association) New(cmdText, association, exchange)

Slide 19

Using the summon question string sSelectQuery = "SELECT * FROM Categories ORDER BY CategoryID"; string sConnectionString = "Initial Catalog=Northwind; Data Source=localhost; Integrated Security=SSPI;"; SqlConnection objConnect = new SqlConnection(sConnectString); SqlCommand objCommand = new SqlCommand(sSelectQuery, objConnect);/* objCommand.CommandTimeout = 15; objCommand.CommandType = CommandType.Text; */objConnect.Open(); SqlDataReader drResults; drResults = objCommand.ExecuteReader() drResults.Close(); objConnect.Dispose();

Slide 20

Command Methods .ExecuteReader() - Returns DataReader .ExecuteNonQuery() - Returns # of Rows Affected .ExecuteXMLReader() - Returns XMLReader Object to Read XML documentation .ExecuteScaler() - Returns a Single Value e.g. SQL SUM work.

Slide 21

The DataReader question DataReader articles are profoundly improved for quick, forward just list of information from an information summon A DataReader is not separated

Slide 22

The DataReader protest Access to information is on a for every record premise. Forward just Read just Does bolster various recordsets

Slide 23

Creating an information peruser SqlDataReader sqlReader; sqlReader = sqlCommand.ExecuteReader(); while (sqlReader.Read()) {/handle, sqlReader( " field " ) } sqlReader.Dispose();

Slide 24

Other Methods GetString(), GetInt() and so forth. GetSqlString(), GetSqlInt32() and so forth. GetValues() IsDBNull() GetSchemaTable()

Slide 25

DataSets In-memory portrayal of information contained in a database/XML Operations are performed on the DataSet, not the information source Can be made automatically, utilizing a DataAdapter or XML construction and archive (or any blend)

Slide 26

Creating DataSets Setup SqlConnection Setup a SqlDataAdapter Create a DataSet Call the .Fill() strategy on the DA

Slide 27

DataAdapters Pipeline amongst DataSets and information sources Geared towards usefulness as opposed to speed Disconnected by configuration Supports select, embed, erase, upgrade charges and strategies

Slide 28

DataAdapters Must dependably indicate a select summon All different orders can be produced or determined

Slide 29

Using the DataAdapter SQLDataAdapter sqlDA = new SqlDataAdapter(); sqlDA.SelectCommand = new SqlCommand ( " select * from creators ", sqlConnection); DataSet sqlDS = new DataSet("authorsTable"); sqlDA.Fill(sqlDS, "authorsTable");

Slide 30

DataAdapters For speed and productivity you ought to set your own InsertCommand, UpdateCommand and DeleteCommand Call GetChanges to seperates the overhauls, includes and erases since the last synchronize. At that point match up each sort.

Slide 31

DataTables A DataSet contains at least one DataTables. Fields are held inside the DataTable. Also, in DataRows, DataColumns.

Slide 32

Sets, Tables and Rows DataSet DataTable DataRow

Slide 33

Using DataTables With a DataTable we can Insert, change and overhaul Search Apply sees Compare Clear Clone and Copy

Slide 34

DataRelations New to ADO.Net Tables inside a DataSet can now have connections, with honesty. Underpins falling overhauls and erases.

Slide 35

DataViews Like a SQL see Single, or different tables Normally utilized with GUI applications by means of Data Binding.

Slide 36

References ADO.Net Programmer\'s Reference Bilbija, Dickenson et al. Wrox Press email :

Slide 37

Thank You!! - Marmagna Desai

View more...