AD A O.N. ET E Access Data Object



Similar documents
Access Data Object (cont.)

ASP.NET Programming with C# and SQL Server

Intermediate ASP.NET Web Development with C# Instructor: Frank Stepanski. Data Sources on the Web

VB.NET - DATABASE ACCESS

Aplicação ASP.NET MVC 4 Usando Banco de Dados

Mastering Visual Basic.NET Database Programming Evangelos Petroutsos; Asli Bilgin

C# Datenbank-Programmierung

Expanded contents. Section 1. Chapter 2. The essence off ASP.NET web programming. An introduction to ASP.NET web programming

Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition

DEVELOPING A PHD MONITORING TOOL USING ASP.NET AND SQL SERVER. A Report Submitted In Partial Fulfillment Of Course BITS C331 Computer Oriented Project

Using IRDB in a Dot Net Project

A Tutorial on SQL Server CMPT 354 Fall 2007

ACDS AIMS Certified Database Specialist Course.

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Bertrand Meyer. C#: Persistence

(VB) - Pro: Designing and Developing Windows Applications Using the Microsoft.NET Framework 3.5

Integrating SAS and Microsoft.NET for Data Analysis

Deleting A Record Updating the Database Binding Data Tables to Controls Binding the Data Table to the Data Grid View...

Database Programming with C# CARSTEN THOMSEN

Crystal Reports for Visual Studio.NET

Transition your MCPD Web Developer Skills to MCPD ASP.NET Developer 3.5 (VB)

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

ASP.NET Using C# (VS2012)

Exam Ref : Developing Windows Azure and Web Services. William Ryan Wouter de Kort Shane Milton

Visual COBOL ASP.NET Shopping Cart Demonstration

How To: Create a Crystal Report from ADO.NET Dataset using Visual Basic.NET

A Static Analysis Framework for Database Applications

ASP.NET Overview. Ken Casada Developer Evangelist Developer & Platform Evangelism Microsoft Switzerland

Crystal Reports. For Visual Studio.NET. Reporting Off ADO.NET Datasets

1. What is SQL Injection?

CRYSTAL REPORTS IN VISUAL STUDIO.NET 2003

Classes para Manipulação de BDs 5

Creating the Product Catalog Part I (continued)

Conexión SQL Server C#

1. Create SQL Database in Visual Studio

Beginning ASP.NET 4.5

Real-World ASP.NET: Building a Content Management System

IBM DB2 XML support. How to Configure the IBM DB2 Support in oxygen

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

SQL injection attacks SQL injection user input SQL injection SQL Command parameters Database account. SQL injection attacks Data Code

Getting Started with Telerik Data Access. Contents

MySQL for Beginners Ed 3

How To Create A Database In Araba

ADO.NET Using C# Student Guide Revision 4.0. Object Innovations Courses 4120 and 4121

THE DESIGN AND IMPLEMENTATION OF AN E-COMMERCE SITE FOR ONLINE BOOK SALES. Swapna Kodali

Oracle Database 11g SQL

SQL Injection. The ability to inject SQL commands into the database engine through an existing application

listboxgaatmee.dragdrop += new DragEventHandler(listBox_DragDrop); ListBox from = (ListBox)e.Data.GetData(typeof(ListBox));

TRANSACÇÕES. PARTE I (Extraído de SQL Server Books Online )

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package Data Federation Administration Tool Guide

Application Development

Before you may use any database in Limnor, you need to create a database connection for it. Select Project menu, select Databases:

SQL and Java. Database Systems Lecture 19 Natasha Alechina

Keywords web applications, scalability, database access

Commercial Database Software Development- A review.

ASP and ADO (assumes knowledge of ADO)

Visual Basic Database Programming

Managing User Accounts

An Overview of SQL CLR

Database Communica/on in Visual Studio/C# using Web Services. Hans- Pe=er Halvorsen, M.Sc.

INTRODUCING ORACLE APPLICATION EXPRESS. Keywords: database, Oracle, web application, forms, reports

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

Oracle Database 10g: Introduction to SQL

5 Airport. Chapter 5: Airport 49. Right-click on Data Connections, then select Add Connection.

TMS RemoteDB Documentation

New 11g Features in Oracle Developer Tools for Visual Studio. An Oracle White Paper January 2008

Developing and Implementing Windows-Based Applications With Microsoft Visual C#.NET and Microsoft Visual Studio.NET

SQL Server Database Web Applications

Building ASP.NET Applications

Oracle Database 10g Express

Chapter 7 -- Adding Database Support

Use the ADO Control in your Visual Basic 6 projects

Thank you for using AD Bulk Export 4!

2311A: Advanced Web Application Development using Microsoft ASP.NET Course 2311A Three days Instructor-led

One method for batch DHI data import into SQL-Server. A batch data import technique for DateSet based on.net Liang Shi and Wenxing Bao

Geodatabase Programming with SQL

Whitepaper. HR Dashboard STRATEGIC VALUE CREATION USING MICROSOFT REPORTING SERVICES YOUR SUCCESS IS OUR FOCUS

Database Communica/on in Visual Studio/C# using ASP.NET Web Forms. Hans- PeBer Halvorsen, M.Sc.

Chapter 4 Accessing Data

MOVING THE SENIOR DEVELOPMENT CLASS FROM WEB DEVELOPMENT TO LIFE CYCLE DEVELOPMENT A CASE FOR VISUAL STUDIO 2005

MS Enterprise Library 5.0 (Logging Application Block)

Programming in C# with Microsoft Visual Studio 2010

Developing and Implementing Web Applications with Microsoft Visual C#.NET and Microsoft Visual Studio.NET

Developing CLR Database Objects

Skills for Employment Investment Project (SEIP)

ADO Connection String Samples. Table of Contents.

Secured Client Portal

SQL Server Administrator Introduction - 3 Days Objectives

4. The Third Stage In Designing A Database Is When We Analyze Our Tables More Closely And Create A Between Tables

Exposed Database( SQL Server) Error messages Delicious food for Hackers

ICAB4136B Use structured query language to create database structures and manipulate data

The Data Access Handbook

Transcription:

ADO.NET Access Data Object

ADO.NET Conjunto de classes que permitem o acesso à base de dados. Dois cenários: Connected Os dados provenientes da base de dados são obtidos a partir de uma ligação que se mantém aberta enquanto percorremos os valores Disconnected Os dados são transferidos da base de dados para memória e após o carregamento a conexão é fechada automaticamente Namespace System.Data 1

.Net Data Providers Providers: SQL Server - System.Data.SqlClient OLE DB - System.Data.OleDb ODBC - System.Data.Odbc Oracle - System.Data.OracleClient. Object: Connection Command DataReader DataAdapter provides connectivity to a data source enables access to database commands to return data, modify data, run stored procedures, and send or retrieve parameter information provides a high-performance stream of data from the data source read-only, forward-only provides the bridge between the DataSet object and the data source. Uses Command objects to execute SQL commands 2

The DataSet object is central to supporting disconnected, distributed data scenarios with ADO.NET. The DataSet is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source The DataSet represents a complete set of data, including related tables, constraints, and relationships among the tables. 3

Arquitectura ADO.NET Relationship between a.net Framework data provider and a DataSet 4

Acesso a Bases de Dados 5

Acesso a Bases de Dados Connected 1. Create a connection SqlConnection, OleDbconnection, 2. Create a command SqlCommand, Oledbcommand, 3. Execute Command 4. Use DataReader 6

Objecto Connection SqlConnection / OleDbConnection string strconn = "data source=localhost; " + "initial catalog=northwind; " + "integrated security=true"; SqlConnection conn = new SqlConnection(); conn.connectionstring=strconn; ConnectionString parameters: Connection timeout Password Data source Persist security info Initial catalog User ID Integrated security Provider Examples: http://www.connectionstrings.com/ 7

Objecto Command SqlCommand / OleDbCommand Represents an SQL statement or stored procedure to execute against a data source. SqlCommand com = new SqlCommand(); com.connection = conn; com.commandtext="select * From Tabela;"; SqlDataReader Info = com.executereader(); Properties: Connection Command Text - Query SQL Parameters 8

Objecto Command Execute SQL commands ExecuteReader Executes commands that return rows - queries. (SELECT) ExecuteNonQuery Executes commands such as SQL INSERT, DELETE, UPDATE, and SET statements. ExecuteScalar Retrieves a single value, for example, an aggregate value from a database (Ex: Count) 9

Data Command private System.Data.OleDb.OleDbConnection myconnection; private System.Data.OleDb.OleDbCommand cmd; String connstr="provider=microsoft.jet.oledb.4.0; Data Source=" + strpath; String strsql="insert into Produtos (IdCat,NomeProd,Preco) Values ('1','" + nomeprod + "'," + "'" + preco +"')" ; myconnection=new System.Data.OleDb.OleDbConnection(connstr); myconnection.open(); cmd=new OleDbCommand (strsql,myconnection); (*) cmd.executenonquery(); myconnection.close(); (*) cmd=new OleDbCommand(); cmd.connection=myconnection; cmd.commandtext=strsql; Constructor or Property 10

Data Command Use parameters in SQL String strsql = "Insert into Produtos (IdCat, NomeProd, Preco) Values (?,?,?)"; myconnection = new OleDbConnection(myConnectionstr); cmd = new System.Data.OleDb.OleDbCommand( ); cmd.connection = myconnection; Parameters cmd.commandtext = strsql; cmd.parameters.addwithvalue("idcat",idcat); cmd.parameters.addwithvalue("nomeprod",nomeprod); cmd.parameters.addwithvalue("preco",preco);? - MS Access @ - MS SQL Server : - Oracle). 11

Date Parameter OleDbCommand cmd = conn.createcommand(); cmd.commandtext = "INSERT INTO facturas (clienteid, datacriacao) VALUES (?,?)"; cmd.parameters.add("cid", 347); OleDbParameter parm = cmd.parameters.add("dt", OleDbType.Date); parm.value= DateTime.Now; cmd.executenonquery(); 12

Objecto DataReader SqlDataReader / OleDbDataReader Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited. To create an OleDbDataReader call the ExecuteReader method of the OleDbCommand object SqlDataReader Info = com.executereader(); DataGrid1.DataSource=Info; forward-only and read-only Properties FieldCount HasRows IsClosed Close GetString GetInt32 13

Objecto DataReader DataSource de Server Controls string sql ="SELECT Nome FROM Categorias"; OleDbConnection conn = new OleDbConnection(connstr); OleDbCommand cmd = new OleDbCommand(sql,conn); conn.open(); OleDbDataReader myreader; myreader = mycommand.executereader(); gridviewobj.datasource=myreader; gridviewobj.databind(); 14

Objecto DataReader Métodos: Read lê um registo do resultado do Query, permite iterar sobre o objecto GetFloat, GetInt, GetString, etc permite aceder aos campos do registo GetSchemaTable Devolve um Data Table com a informação do Schema do resultado do Query while (dtreader.read()) { HyperLink hlink=new HyperLink(); hlink.text=dtreader.getstring(1); // (string)dtreader[ NomeCat ]; hlink.navigateurl="http://localhost/produtos.aspx?prod= "+dtreader.getint32(0); Panel1.Controls.Add(hlink); Panel1.Controls.Add(new LiteralControl("<P/>")); } 15

Data-Bound Web Server Controls ASP.NET Data-Bound Web Server Controls GridView displays data as a table and provides the capability to sort columns, page through data, and edit or delete a single record DetailsView renders a single record at a time as a table and provides the capability to page through multiple records, as well as to insert, update, and delete records. FormView renders a single record at a time from a data source and provides the capability to page through multiple records, as well as to insert, update, and delete records. FormView control does not specify a built-in layout. 16

Data-Bound Web Server Controls Repeater renders a read-only list from a set of records returned from a data source. Repeater control does not specify a built-in layout. DataList renders data as table and enables you to display data records in different layouts, such as ordering them in columns or rows ASP.NET Data-Bound Web Server Controls Overview https://msdn2.microsoft.com/en-us/library/ms228214.aspx 17