Database Application Programming (C#) Chris North CS 4604: DB.

Slides:



Advertisements
Similar presentations
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Advertisements

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 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
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.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
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.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Introduction to ADO.Net and Visual Studio Database Tools
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Some Basic Database Terminology
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
1 Introducing Database Access from Web Applications by Sally Kyvernitis.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
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.
Overview of ADO.NET with the.NET Framework Scalable Development, Inc. Building systems today that perform tomorrow.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
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)
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
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.
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
ASP.NET - accessing the database - datareader vs dataset - datagrid vs datalist - brief look at web matrix.
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.
User Interface Programming in C#: Model-View-Controller Chris North CS 3724: HCI.
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:
ADO.NET Part 2. Slide 2 Overview Slide 3 Introduction to the DataGridView Control It’s a two-dimensional grid containing rows and columns Its use in.
Object Oriented Software Development 10. Persistent Storage.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
 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.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
ASP.NET - insert - delete -update DataTables (disconnected datasets) Shopping Basket.
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.
1 11/15/05CS360 Windows Programming ADO.NET Continued.
HNDIT Rapid Application Development
ADO.NET in VB.NET 2005 ITE 370 4/26/2017.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
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
 2 Data Object Library approaches ◦ DAO (Data Access Objects)  Original access strategy (up to VB6)  Closely linked to MS Access ◦ ADO (ActiveX Data.
 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.
Data Access with ADO.NET
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
ADO.NET Accessing Databases in VS.NET
Brief description on how to navigate within this presentation (ppt)
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Database Objects 1/12/2019 See scm-intranet.
Chapter 10 ADO.
Database Applications
Chapter 10 Accessing Database Files
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Database Application Programming (C#) Chris North CS 4604: DB

GUI/DB Application Model Database DataSet object DB Connection DB Adapter DB SQL Query Win Form DataGrid control

Architecture Layers Database DB EngineDBMS UI DB Driver DB API Application Data Objects App UI SQLserver, Access Database SQLserver, Jet ODBC, OleDB, JDBC ADO, JDBC WinForms, Swing DB Admin App User OS Application Internet, local … … …

C# DataBase Access (ADO.net) OleDB, ODBC, SQLdb, … Steps to get data: 1.dbConnection: connect to DB 2.dbCommand: SQL query text 3.dbAdapter: executes query 4.DataSet: resulting data Steps to display data: Bind to UI control, e.g. DataGrid or Manual data processing DB Alternative: DataReader, retrieve data incrementally

C# DB Example Get data: Using System.Data.OleDb;// “Jet” = MS Access DB driver con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/mydb.mdb”); cmd = new OleDbCommand("SELECT * FROM mytable”, con); // SQL query adpt = new OleDbDataAdapter(cmd); data = new DataSet( ); adpt.Fill(data); // execute the query and put result in ‘data’ Display data: dataGrid1.DataSource = data.Tables[0];// show the table in the grid control MessageBox.Show(data.Tables[0].Rows[0][5].ToString( )); // or process manually, this is row 0 col 5

DataSet vs. DataReader DataSet: Like 2D array: a[r][c] Full dataset read from DB at query execution time Dataset cached locally in mem Can disconnect from DB Implemented using DataReader (Adapter) + random data access - Limited scalability - initial read very slow DataReader: (standard) 1 row at a time No local memory storage Fetch each row from DB on demand “cursor” = current row Must stay connected to DB + scalability - each row slow - random access difficult

Object Model DataSet: Tables[n] –Rows[r] columns[c] –Value, type, … –Columns info [c] Name, type, … DataReader: (standard) Columns[c] (current row) –Value, type, … Columns info [c] –Name, type, … Cursor: –moveNext, MovePrev, moveTo –EOF

Cursors Forward only vs. forward/back vs. random access Read only vs. writeable …

Connections Connection strings: Tons o examples: Con.open( ) Queries here Con.close( ) // connections consume resources Adapter.Fill( ) does open/close automatically

Commands (Queries) Command Types: SQL Query: »Relation: SELECT »Scalar: SELECT that returns 1 row, 1 col »Non-query: INSERT, UPDATE, DELETE Table name View name Rdr = Cmd.ExecuteReader( );

Query Parameters Want to substitute a parameter value into a query Dynamic SQL query construction: cmd = new OleDbCommand( "SELECT * FROM table WHERE myAttr = " + myValue, con); but: what if myValue contains weird chars? Parameterized query: (more robust, reusable) cmd = new OleDbCommand( "SELECT * FROM table WHERE myAttr = ?", con); // ? = parameter cmd.Parameters.Add(“?”, myValue); // parameter value Or, put param query in DB as view / stored procedure: cmd = new OleDbCommand("MyStoredQuery", con);// name of view cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("?", myValue);// parameter value

DataBound UI Controls Display a table: DataGrid Display a column: DataList listBox ComboBox Display a cell value: (of current row) TextBox Can bind any property of any UI control to any DB column DataGrid control -scroll, sort, edit, …

Manual data processing foreach(DataRow r in dataSet1.Tables[0].Rows) // for each row { doSomethingWith(r[“columnName”]); //or: foreach(Object v in r.ItemArray) // for each column doSomethingWith(v); }

Saving Data Changes Manual update/insert/delete queries: cmd = new OleDbCommand(“UPDATE table SET myAttr=value WHERE id=idval”, con); cmd.ExecuteNonQuery();// query does not return data. Adapters and bound UI Controls: User can edit in DataGrid, etc. Writes DataSet changes to DB on Update( ) method Must have param update/insert/delete commands in Adapter cmd = new OleDbCommand(" UPDATE table SET attr1=?, attr2=? WHERE id=?", con); cmd.Parameters.Add(new OleDbParameter(“?”, …, “attr1”, DataRowVersion.Current )); cmd.Parameters.Add(new OleDbParameter(“?”, …, “attr2”, DataRowVersion.Current )); cmd.Parameters.Add(new OleDbParameter(“?”, …, “id”, DataRowVersion.Original )); adpt.UpdateCommand = cmd; adpt.Update(data);// analogous to adpt.Fill(data);

Getting DB Schema Info Get list of tables in the DB: con.Open(); System.Data.DataTable t = con.GetOleDbSchemaTable( System.Data.OleDb.OleDbSchemaGuid.Tables, new object[]{null,null,null,"TABLE"} );

Visualization Draw graphics in Paint event Scale data coords to pixel coords E.g. scatterplot: foreach(DataRow r in dataSet1.Tables[0].Rows) // for each row { x = r[“attr1”] * Width / maxValue1; // Scale x,y to fit into window y = Height - r[“attr2”] * Height / maxValue2; // also flip y axis e.Graphics.FillEllipse(Brushes.Red, x, y, 10, 10); }

Interaction Mouse Events Scale mouse coords back into data coords Parameterized SQL query E.g. 2 clicks define a rectangle: Rect.left = click1.x / Width * maxValue1;// scale click x,y back to data range … SELECT * FROM table WHERE attr1 >= {rect.left} AND attr1 <= {rect.right} AND attr2 >= {rect.top} AND attr2 <= {rect.bottom} doSomething with results… Refresh( ); // repaint the window to show results in Paint event