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.

Slides:



Advertisements
Similar presentations
Direct Data Access, Data Binding. Content Direct Data Access Data Binding Muzaffer DOĞAN - Anadolu University2.
Advertisements

 Open the Paradise.exe file  Application displays records in the Books database  Allows the store manager to enter an author’s name (or part of a name)
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
1 Web-Enabled Decision Support Systems Advance Topics in Database Connectivity Prof. Name Position (123) University Name.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
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.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
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.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 8 Using Repetition with Loops and Lists. Class 8: Loops and Lists Write Do loops to execute statements repeatedly Write For loops to execute statements.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Databases and LINQ Visual Basic 2010 How to Program 1.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Chapter 10 Managing Data with ASP.NET. ASP.NET 2.0, Third Edition2.
BIM211 – Visual Programming Database Operations II 1.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
BİL528 – Bilgisayar Programlama II Database Operations II 1.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
CIS 375—Web App Dev II ASP.NET 10 Database 2. 2 Introduction to Server-Side Data Server-side data access is unique in that Web pages are basically ___________.
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.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
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.
Neal Stublen Tonight’s Agenda  Database Errors  Parameterized queries  ToolStrip control  Master-detail relationships  Custom.
Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Module 3: Performing Connected Database Operations.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
Reference: “ASP.NET 2.0 Illustrated” by Alex Homer and Dave Sussman. -ch3 illustrated book
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload.
Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic nd Edition.
HNDIT Rapid Application Development
WaveMaker Visual AJAX Studio 4.0 Training Java Script Events.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
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.
Coding ADO.NET Objects: Connection, Command, DataReader.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
4: DataGrid, DataView, and ListView
© 2013, Mike Murach & Associates, Inc.
Programming the Web Using ASP.Net
Active Data Objects Binding ASP.NET Controls to Data
VB.NET Using Database.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Lecture Set 10 Windows Controls and Forms
Chapter 10 ADO.
Database Applications
Active Data Objects Binding ASP.NET Controls to Data
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

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 unbound mode was mentioned earlier in the course Now, we will use it in bound mode

Slide 4 The DataGridView Control (Capabilities) Displays rows from a single table ( DataTable ) or view Allows editing (add, change, delete) A rich set of events for error handling A rich set of properties and objects for formatting

Slide 5 The DataGridView Control (Binding) Set the DataSource and DataMember properties These can be A DataSet ( DataSource ) and DataTable ( DataMember ) A BindingSource ( DataSource – the DataMember is not set)

Slide 6 The DataGridView Control (Formatting) Much can be done through the user interface

Slide 7 The DataGridView Control (Columns Editor)

Slide 8 DataGridView (Row Events) In all, there are about 100 different events Only selected events are of interest to us RowEnter fires as a row gets input focus RowLeave fires as a row loses focus RowValidating fires after RowLeave and provides the chance for validation This event can be cancelled

Slide 9 DataGridView (Row Events 2) Event arguments are complex types DataGridViewCellEventArgs RowIndex contains the 0-based index of the row ColIndex contains the 0-based index of the column DataGridViewCellCancelEventArgs Set Cancel to true to cancel the subsequent events

Slide 10 DataGridView (Row Events 3) See tblLocationDataGridView event handlers in IS389ADOPart 2

Slide 11 DataGridView (Cell Events 1) CellEnter fires when a cell gets focus CellBeginEdit fires when editing begins CellEndEdit fires when editing ends CellLeave fires after end edit when cell loses focus

Slide 12 DataError Event Remember that in this context, the DataGridView is bound to a data source Trying to store type invalid values in the underlying DataTables will throw exceptions Handle this event to handle those exceptions

Slide 13 Using the OleDbCommand Object ( ExecuteScalar ) Remember the ExecuteScalar method returns a single value Use to get a max ID value

Slide 14 ExecuteScalar (Example) Get Max of field fldBoreHoleID in tblBoreHoleData System.Data.OleDb.OleDbCommand oCmd = new System.Data.OleDb.OleDbCommand(); oCmd.CommandType = CommandType.Text; oCmd.CommandText = "SELECT MAX(fldBoreHoleID) FROM tblBoreholeData"; oCmd.Connection = tblBoreholeDataTableAdapter.Connection; oCmd.Connection.Open(); int i; i = (int) oCmd.ExecuteScalar(); oCmd.Connection.Close();

Slide 15 Using the OleDbCommand Object ( ExecuteNonQuery ) Use to Execute INSERT, UPDATE, or DELETE commands that do not return rows Example 1: System.Data.OleDb.OleDbCommand oCmd = new System.Data.OleDb.OleDbCommand(); oCmd.CommandType = CommandType.Text; oCmd.CommandText = "INSERT INTO tblCasIndex (fldCASIndexNumber, fldChemicalName, fldCASRegNo, fldCarcinogenic) VALUES (123,'abc','def',false)"; oCmd.Connection = tblBoreholeDataTableAdapter.Connection; oCmd.Connection.Open(); oCmd.ExecuteNonQuery(); oCmd.Connection.Close();

Slide 16 Using the OleDbCommand Object with Parameters Unlike the previous example, we generally don’t want to hardcode the data values This is where parameters come in Add one parameter for each dynamic field

Slide 17 Creating a Parameter An OleDbParameter has a Name Data type Size Mapping field Example: System.Data.OleDb.OleDbParameter prop = new System.Data.OleDb.OleDbParameter( "fldCASIndexNumber",System.Data.OleDb.O leDbType.Integer,0,"fldCASIndexNumber") ;

Slide 18 Adding the Parameter Each parameter must be added to the Parameters collection of the OleDbCommand Example oCmd.Parameters.Add(prop);

Slide 19 Filling in the Parameter Values Set the Value property of a particular parameter oCmd.Parameters["fldCASIndexNumber"].Value = 234; oCmd.Parameters["fldChemicalName"].Value = "XXX"; oCmd.Parameters["fldCASRegNo"].Value = "YYY"; oCmd.Parameters["fldCarcinogenic"].Value = true;

Slide 20 A Parameterized insert statement The INSERT statement looks like this oCmd.CommandText = "INSERT INTO tblCasIndex (fldCASIndexNumber, fldChemicalName, fldCASRegNo, fldCarcinogenic) VALUES (?,?,?,?)";

Slide 21 Using the OleDbDataReader Place an SQL SELECT statement in the OleDbcommand Call ExecuteReader to create the forward- only reader Call Read to read each record Then call the various Get method to get the value of each field

Slide 22 Programmatically Selecting Records See Example