Vous êtes sur la page 1sur 3

Data Access Programming applications can access data from a variety of data sources o in-memory data structures (e.g.

., variables, arrays, lists, etc.) o data files in various formats (e.g., plain text, formatted text, binary, spreadsheets, XML, etc.) o databases (legacy, RDBMS, ORDBMS) o data services (e.g., applications, remote data objects, web services, etc.) o hardware devices the nature of the data source dictates how data is accessed and what can be done with the data o direct manipulation, library routine calls, SQL queries, method calls, register-based I/O, memory-mapped I/O, etc. o sequential access, random access o field-oriented access, line-oriented access, record-oriented access, block-oriented access o read-only access, write-only access, read-write access o online access, offline access, local access, remote access software development environments provide (or provide support for) some data access technology or standard o the standard defines data access components which specify how data can be accessed/manipulated programmatically in the environment library routines in traditional environments library objects in OO environments (typically as abstract base classes and/or interfaces) o specific data source vendors (e.g., MySQL, Oracle, SQL Server, etc.) define data providers (a.k.a. drivers) compatible with the standard; these drivers implement the functionality specified by the standard, as applied to the specific backend technology o the developers then make use of the functionality provided by the data access components, and the data providers map the operations to the specific backend data source, thus giving the developers a consistent interface to data access/manipulation, without having to be concerned about all the specific details of the backend technology o common data access technologies: Data Access Objects (DAO) Open Database Connectivity (ODBC) ActiveX Data Objects (ADO) Object Linking and Embedding - Database (OLEDB) Java Database Connectivity (JDBC)

ADO.NET data access architecture for the .NET Framework software components included in the Microsoft .NET Framework BCL which can be used by programmers to access data and data services allows access to relational or non-relational data sources architecture:

o .NET Framework Data Provider Connection used to establish a connection to a data source Command used to issue operations to the data source (retrieve data, manipulate data, run stored procedures, send or retrieve parameter information, etc.) Parameter used to provide arguments to commands DataReader used to provide record-oriented read-only, forwardonly access to a record set returned by data retrieval operation DataAdapter used as a bridge to transfer data between a data source and a data set Microsoft .NET Framework comes bundled with data providers for SQL Server, Oracle, OLEDB, and ODBC; third-party vendor providers are also available (e.g., Connector/NET for MySQL) o DataSet designed for data access independent of any data source represents data as a simple, in-memory relational database can be used with multiple or differing data sources, can save its data to or be populated from XML, used to manage data local to an application, provide for disconnected access to data, etc.

using System; using System.Data.OleDb; namespace DataAccessSample { class Program { static void Main(string[] args) { OleDbConnectionStringBuilder ocsb; OleDbConnection conn; OleDbCommand cmd; OleDbDataReader reader; OleDbParameter p, q; ocsb = new OleDbConnectionStringBuilder(); ocsb["Provider"] = "Microsoft.Jet.OLEDB.4.0"; ocsb["Data Source"] = "database/SampleDB.MDB"; string connStr = ocsb.ConnectionString; conn = new OleDbConnection(connStr); conn.Open(); string sSQL = "SELECT prodid, prodname, price FROM products"; cmd = new OleDbCommand(sSQL, conn); reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); decimal price = reader.GetDecimal(2); Console.WriteLine("{0,-5} {1,-30} {2,10:#,0.00}", id, name, price); } reader.Close(); string uSQL = "UPDATE products SET price = price * 1.1"; cmd = new OleDbCommand(uSQL, conn); cmd.ExecuteNonQuery(); string iSQL = "INSERT INTO products VALUES(?, ?, ?)"; cmd = new OleDbCommand(iSQL, conn); p = cmd.Parameters.Add("p1", OleDbType.Integer); p.Value = 5000; q = cmd.Parameters.Add("p2", OleDbType.VarChar); q.Value = "scissors"; cmd.Parameters.Add("p3", OleDbType.Decimal).Value = 18.75; cmd.ExecuteNonQuery(); conn.Close(); } } }

Vous aimerez peut-être aussi