ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

Programming with ADO.NET By Sam Nasr April 27, 2004 Programming with ADO.NET By Sam Nasr April 27, 2004.
ADO vs ADO.NET ADOADO.NET Client/server coupledDisconnected collection of data from data server Uses RECORDSET object (contains one table) Uses DATASET.
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Introduction to Database Processing with ADO.NET.
1 ADO.NET. 2.NET Framework Data Namespaces System.Data –Base set of classes and interfaces for ADO.NET System.Data.Common –Classes shared by the.NET Data.
.NET Mobile Application Development Data in Distributed Systems Accessing Data with.NET.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
In C# program Before you can start using the ODBC class definitions, you will need to include the right module. using System.Data.Odbc; // ODBC definitions.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
Intro to C#.net and EF Ilan Shimshoni. The Three Faces of ADO.NET The connected layer – Directly connecting to the DB The disconnected layer – Using datasets.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
Accessing SQL Server and OLE DB from.NET Svetlin Nakov Telerik Corporation
A Simple Introduction. What is ADO.net? First the word ADO stands for ActiveX Data Objects And it is an integral part of.Net Framework of Microsoft hence.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
PART 1 CREATING THE PRODUCT CATALOG. ROADMAP FOR THIS CHAPTER To implement the departments list, you’ll start with the database and make your way to the.
Neal Stublen Populating a Database  SQLExpress should be installed with Visual Studio  The book provides a.sql file for populating.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
ASP.NET Rina Zviel-Girshin Lecture 5
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
Module 7: Accessing Data by Using ADO.NET
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
Module 3: Performing Connected Database Operations.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
C# Programming in Depth Prof. Dr. Bertrand Meyer March 2007 – May 2007 Chair of Software Engineering Lecture 10: Database Lisa (Ling) Liu.
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
Why ADO.NET Not your father’s Data Access.
Mauricio Featherman, Ph.D. Washington St. University
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
1 11/15/05CS360 Windows Programming ADO.NET Continued.
HNDIT Rapid Application Development
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
C# .NET Software Development
Active Data Objects Using.Net ADO.Net Farooq Ahmed Amna Umber Summayya Shehzad.
Module 5 Data Classes DataView – DataGridView Control 1.
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 The SqlCommand Object ADO.NET - Lesson 03  Training time: 15 minutes  Author:
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
.NET Data Access and Manipulation
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
ASP.NET Programming with C# and SQL Server First Edition
Data Access with ADO.NET
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET and Stored Procedures
ADO.NET Framework.
Programming the Web Using ASP.Net
ADO.Net and Stored Procedures
Tonga Institute of Higher Education
Chapter 10 ADO.
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Presentation transcript:

ADO. NET

What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical ADO, there are some new concepts such as the Dataset. ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical ADO, there are some new concepts such as the Dataset.

Introduction to ADO.NET MS-AccessMS-SQLDescription NameSpaceSystem.Data.OleDbSystem.Data.SqlClient ConnectionOleDbConnectionSqlConnection opening a connection to the database CommandOleDbCommandSqlCommand invoking SQL commands or stored procedures RecordSetOleDbDataReaderSqlDataReader connected forward-only access to database DataSetOleDbDataAdapterSqlDataAdapter populating a Dataset. Stored Procedure OleDbParameterSqlParameter specifying parameter to a stored procedure ransactionOleDbTransactionSqlTransaction programming database transactions

Process of using DB (1)  Import Namespace  Make Connection  Open Connection  Send Query  Execute Query  Store result  Populate data in UI  Close connection

Process of using DB (2) SqlConnection conn = new SqlConnection(connstr); //using(SqlConnection conn = new SqlConnection(connstr)) conn.Open(); SqlCommand cmd = new SqlCommand(SQLstr,conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { listBox1.Items.Add(reader[1].ToString()); listBox1.Items.Add(reader[1].ToString());}conn.Close();

Connection(1) Connection String   MS-SQL string connstr = "server=SERVERNAME;uid=USERID;pwd=PASSWORDr;datab ase=DBNAME;"; string connstr = "server=rainnysea;uid=testuser;pwd=testuser;database=Teststd; ";   MS-Acess string connstr = "Provider=ProviderName&Version;Data Source=FileNameOnServer"; string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\cs440\\Test\\data\\xyz.mdb;";

Connection(2) database connections are an important resource and you should explicitly close the connection. conn = SqlConnection(ConnString); try{ // open the connection to the database conn.Open(); // do something with the database } catch (Exception e) { // report error } finally { conn.Close( ); }

Execute Method on the Command ExecuteNonQuery( ) used when no records are expected in the output e.g., insert or update sql commands. ExecuteReader( ) returns a connected DataReader (actually DataReader interface) ExceuteScalar( ) returns a single row, useful when verifying login for a particular user. ExecuteXmlReader( ) returns an XML reader.

Command(1) – ExecuteScalar() ExecuteScalar() ExecuteScalar() SqlCommand cmd = new SqlCommand(qry, this.con ); new SqlCommand(qry, this.con ); Object obj = cmd.ExecuteScalar(); // returns one row // returns one row

Command(2) – ExecuteReader() ExecuteReader() ExecuteReader() SqlCommand cmd = new SqlCommand(sql,conn); new SqlCommand(sql,conn); SqlDataReader reader = cmd.ExecuteReader();

Command(3) – ExecuteNonQuery() ExecuteNonQuery() ExecuteNonQuery() SqlCommand cmd = new SqlCommand(sql,conn); new SqlCommand(sql,conn); int cntrows = cmd.ExecuteNonQuery();

Data Stored Object(1) DataReader It present a forward-only stream of data to the application. DataSet It is an in-memory representation of a collection of related data tables. It can be generated using the help of a DataAdapter or filled dynamically by the application DataAdapter A class that is used to fill DataSet object from a data source.

Data Stored Object(2) DataReader Data Source Data Reader Application DataSet Data Source Data Set Application 1Application 2 Data Adapter

What is “Data Set”? A Dataset is a disconnected object that can potentially contain all or part of the database including tables, constraints and their relationships. Thus for using databases in web applications, Dataset can provide a much higher performance for mostly read-only type of data. The DataSet class can further use DataTable, DataRow, DataColumn, DataRelation and Constraint classes to define its offline data.

What is ths “Data Adapter”? DataAdapter class acts as the communication point between the DataSet And tha database. DataAdapter class acts as the communication point between the DataSet And tha database. This object is created much the same way as the Command object. This object is created much the same way as the Command object. Fill() method fills DataSet with data obtained from SQL query. Fill() method fills DataSet with data obtained from SQL query.

DataSet(1) DataSet DS = new DataSet(); SqlDataAdapter Adapter = new SqlDataAdapter(qry, conn); new SqlDataAdapter(qry, conn); Adapter.Fill(DS, tblName);

DataGrid Control(1) displays data in a series of rows and columns. displays data in a series of rows and columns. displaying either a single table or the hierarchical relationships between a set of tables. displaying either a single table or the hierarchical relationships between a set of tables. update the data in the bound DataSet, the DataGrid control reflects the changes. update the data in the bound DataSet, the DataGrid control reflects the changes.

DataGrid Control(2) dataGrid.DataSource = dataGrid.DataSource = dataset.DefaultViewManager; dataset.DefaultViewManager; dataGrid.DataSource = dataGrid.DataSource = dataset.Tables[“tablename"].DefaultView ; dataset.Tables[“tablename"].DefaultView ;

DataGrid Control(2) dataset.Relations.Add("CategoryProducts",ds.Tables["category"].Columns["catID"],ds.Tables["product"].Columns["catID"]); //(relationship name, Parent column name, Child column name)

Parameterized query(1)  Construct the SqlCommand command string with parameters.  Declare a SqlParameter object, assigning values as appropriate.  Assign the SqlParameter object to the SqlCommand object's Parameters property.

Parameterized query(2) str = "update tblCategory set catdesc set catdesc where catdesc where catdesc SqlCommand cmd = new SqlCommand(str, Conn()); new SqlCommand(str, Conn()); cmd.Parameters.Add(new

Stored Procedure(1)  A pre-defined, reusable routine that is stored in a database.  Accept input parameters and return multiple values.  Reduced client/server traffic.

Stored Procedure(2) CREATE PROCEDURE as datatype) AS as datatype) AS [ Insert into tblcategory(catdesc) [ Insert into tblcategory(catdesc) // SQL Query // SQL QueryGO

Stored Procedure(3)  create a command object identifying the stored procedure.  set the command object so it knows to execute a stored procedure.  add parameter to command, which will be passed to the stored procedure.

Stored Procedure(4) SqlCommand cmd = new SqlCommand("cateIns", Conn() ); new SqlCommand("cateIns", Conn() ); cmd.CommandType = CommandType.StoredProcedure; CommandType.StoredProcedure;cmd.Parameters.Add (new (new SqlDbType.VarChar,50,"catDesc")); SqlDbType.VarChar,50,"catDesc")); cmd.Parameters[0].Value = newname;