ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.

Slides:



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

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.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
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.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Introduction to Structured Query Language (SQL)
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
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:
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, VB.Net Database Tools and Data Binding ISYS546.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
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.
ITS 328 CHAPTER 3: STORING DATA IN MEMORY 1. Storing Data in Memory After today you will be able to: ◦Explain how a DataTable stores data ◦Add new data.
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)
Neal Stublen Populating a Database  SQLExpress should be installed with Visual Studio  The book provides a.sql file for populating.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
.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.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
Connecting to Data Sources Using ADO.NET Dr. Awad Khalil Computer Science & Engineering Department AUC.
CHAPTER EIGHT Accessing Data Processing Databases.
Introduction to Database Development Using Borland Data Providers 2128 Martin Rudy.
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.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
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.
Module 4: Building DataSets. Overview Working in a Disconnected Environment Building DataSets and DataTables Binding and Saving a DataSet Defining Data.
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)
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
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.
Mauricio Featherman, Ph.D. Washington St. University
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
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.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic nd Edition.
HNDIT Rapid Application Development
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.
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.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Introduction to Database Processing with ADO.NET
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Introduction to Database Processing with ADO.NET
Visual Basic 2010 How to Program
ADO.NET Framework.
Active Data Objects Binding ASP.NET Controls to Data
VB.NET Using Database.
Tonga Institute of Higher Education
CIS16 Application Programming with Visual Basic
CIS16 Application Programming with Visual Basic
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Active Data Objects Binding ASP.NET Controls to Data
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

ADO.NET Tools and Wizards

Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances on a form

Slide 3 Configuring a Data Source (Steps 1) Display the Data Sources window Click to begin creating a new data source

Slide 4 Configuring a Data Source (Steps 2) Connect to a database

Slide 5 Configuring a Data Source (Steps 3) Create a new connection or select an existing one

Slide 6 Configuring a Data Source (Steps 4) Select the correct data source

Slide 7 Configuring a Data Source (Steps 5) Select the database filename

Slide 8 Configuring a Data Source (Steps 6) Configured connection

Slide 9 Configuring a Data Source (Steps 7) Use local database copy

Slide 10 Configuring a Data Source (Steps 8) Save the connection string

Slide 11 Configuring a Data Source (Steps 9) Select the objects to include

Slide 12 Configuring a Data Source (Steps 10) Configured data source

Slide 13 Creating Bound Control Instances (Introduction) Bound control instances are created by dragging a field (or table) from the Data Sources window to the form

Slide 14 Creating Bound Control Instances (Illustration)

Slide 15 Actions Performed (Introduction) Visual Studio performs a vast amount of work behind the scenes The BindingSource was created A BindingNavigator was created A DataSet was generated Code to populate the DataSet The TableAdapter was created A Connection was generated

Slide 16 The BindingSource (Introduction) The BindingSource was new to.NET 2.0 One purpose is to provide currency (current record) management DataSets and DataTables do not provide currency management It’s methods are used to locate a record in a particular DataTable The BindingSource can also be used to add, change, and delete list items Changes are propagated to the underlying data source ( DataSet and DataTable )

Slide 17 The BindingSource (Properties) Two properties are significant The DataSource property contains the name of the DataSet The DataMember property contains the name of a database table from the DataSet

Slide 18 The BindingSource (Illustration)

Slide 19 The BindingSource Class (Members) MoveFirst, MovePrevious, MoveNext, MoveLast methods perform navigation Current gets the current item from the database table

Slide 20 The BindingNavigator (Introduction) The BindingNavigator provides a user interface for the BindingSource Control instances are typically bound to the navigator items

Slide 21 The BindingNavigator (Properties)

Slide 22 The BindingNavigator (Using) Set the BindingSource property to a previously configured BindingSource Set the value of the various items

Slide 23 Definition ( DataSet ) It’s an in-memory representation of one or more tables in a database It’s created by a data adapter It’s used by the BindingSource It can be accessed programmatically

Slide 24 What’s in a DataSet

Slide 25 Working with the Schema Definition The editor shown in the preceding figure is used to work with Schema Definition files It is initially configured using the underlying database and database relationships It’s possible to add queries, relationships and other items We won't do that here

Slide 26 DataSet Visual Studio created a Schema Definition File This XML document describes the tables in the DataSet and their relationships Visual Studio created a strongly typed DataSet class An instance of the DataSet class was also created

Slide 27 DataSet Class (Types) DataSets are either typed or untyped Untyped DataSet Reference tables and fields through their corresponding collections Typed DataSet Typed DataSets are derived from the System.Data.DataSet class Contains additional properties and methods that allow references to tables and fields directly by name

Slide 28 DataSet Properties Boolean CaseSensitive property controls whether String comparisons are made in a case sensitive or case insensitive way DataSetName property defines the name of the DataSet EnforceConstraints property defines whether ADO.NET checks constraint rules when adding, changing, or deleting data Tables property returns the collection of DataTable objects in the DataSet

Slide 29 DataSet Methods (1) AcceptChanges method causes any changed records to be marked as unchanged records Use to synchronize database with DataSet Clear method removes all rows from all tables in the DataSet Clone method makes a copy of the DataSet schema (structure) Data is not copied Copy method copies both the schema and the data from a DataSet Creates an exact copy of the original DataSet

Slide 30 DataSet Methods (2) GetChanges method (overloaded) examines an existing DataSet and returns a new DataSet containing only the changed records Returns null if DataSet does not contain changes HasChanges method returns a Boolean value indicating whether the DataSet has pending changes RejectChanges method causes any pending changes to be cancelled, restoring any data to their original values

Slide 31 DataTable Class (Introduction) A DataSet object typically contains one or more DataTable objects It’s basically a database table DataTable object contains one or more DataColumn objects representing each column

Slide 32 DataTable (Properties) CaseSensitive property of the DataTable has the same value as the CaseSensitive property of the parent DataSet Columns property contains a reference to a DataColumnCollection Use to reference each column HasErrors property ( Boolean ) is set to True if any of the rows contain errors PrimaryKey property contains an array of DataColumn objects Rows property is a collection having a data type of DataRowCollection

Slide 33 DataTable ( NewRow Method) The NewRow method creates a new DataRow object Method uses schema information obtained from the DataTable itself Calling the NewRow method creates a new DataRow object DataRow contains the same number of DataColumn objects as exist in the underlying DataTable

Slide 34 DataTable (Events) ColumnChanging event fires just before a new value is stored in a particular column ColumnChanged event fires after a value is stored in a column, ColumnChanged event fires after the ColumnChanging event RowChanging event fires before a new value is stored in a row RowChanged event fires after a new value has been stored in a row

Slide 35 DataSet, DataTable, DataColumn Relationships

Slide 36 DataTable (Example) Reference a DataTable using a numeric index and string key DataTable dtCustomers; dtCustomers = dsCurrent.Tables[0]; dtCustomers = dsCurrent.Tables["tblNames"];

Slide 37 DataRowCollection Contains the collection of rows in the DataTable Properties Count property gets the number of rows in the collection (records in the DataTable ) Count property is 1-based Item property (indexer) returns a row having the specified index Index is 0-based

Slide 38 DataRowCollection Methods Add method adds a new DataRow to the end of the Rows collection Clear method removes all of the DataRow objects from the Rows collection Removes all of the rows from the underlying DataTable Find method locates a single DataRow in the Rows collection Remove method removes a DataRow in the Rows collection RemoveAt method has the same purpose as the Remove method Accepts the numeric index of the row to remove as its one argument

Slide 39 DataTable and Rows Relationship

Slide 40 DataRow Class Each row in the Rows collection has a data type of DataRow Item property gets or sets the value for a particular column in a DataRow Item property accepts one argument RowState property indicates whether the DataRow is a new row, a deleted row, or a row whose contents have been modified Delete method of the DataRow class marks the row for deletion Row is not deleted until the AcceptChanges method of the DataSet or DataTable is called

Slide 41 Navigating the DataTable

Slide 42 Modifying Data in a DataTable Modifying the records in a DataSet and its DataTable(s ) and recording those changes back to the database is a two-step process First, add, change, and delete records in the DataTable Second, record those changes back to the database using the Update method of the OleDbDataAdapter

Slide 43 Adding a Row to a DataTable Create a new DataRow object by calling the NewRow method of the DataTable class The NewRow method creates a new DataRow object with the same schema as the underlying DataTable Call the Add method of the Rows collection to add the row to the DataTable

Slide 44 Adding a Row to a DataTable Example DataRow drCurrent; drCurrent = dtCustomers.NewRow(); drCurrent["fldCustomerNumber"] = 99; drCurrent["fldFirstName"] = "Joe"; drCurrent["fldLastName"] = "Bob"; dtCustomers.Rows.Add(drCurrent);

Slide 45 Modifying a DataRow Using an index to the Rows collection, reference a field within that row Example Reference the field named fldID in the first row of the DataTable named dtNames dtCustomers.Rows[0]["fldLastName"] = "Marty";

Slide 46 Deleting a Row from a DataTable To delete a row from a DataTable, call the Delete method of the DataRow class Example 1 dtCustomers.Rows[0].Delete(); Example 2 DataRow drCurrent; drCurrent = dtCustomers.Rows[0]; drCurrent.Delete();

Slide 47 The Strongly Typed DataSet Class (Introduction) The code for the DataSet appears here

Slide 48 Benefits of Strongly Typed DataSets A strongly typed DataSet is one that derives from the System.Data.DataSet class It contains additional properties and methods to reference the tables and fields in that DataSet Reduces coding complexity Property and method names based on the names of the underlying database tables and fields Typed DataSets prevent runtime type conversion errors

Slide 49 Elements of a Typed DataSet (1) A typed DataSet is merely a custom DataSet that derives from the System.Data.DataSet class This class is automatically generated when the DataSet is generated Do not modify this file directly

Slide 50 Importance of Typed DataSets Exposes properties and methods allowing access to each DataTable, its rows, and the fields in those rows by name Properties and methods have data types corresponding to the data type of the underlying table, row, and field

Slide 51 The TableAdapter The TableAdapter is part of the strongly typed DataSet Is used to simplify the processing of the OleDbDataAdapter It allows dynamic queries to be processed

Slide 52 OleDbDataAdapter Class (Introduction) OleDbDataAdapter works in conjunction with the DataSet class to read and write data Commands are sent over a connection Data is retrieved into a DataSet Commands to insert, update, or delete data return nothing

Slide 53 OleDbDataAdapter (Properties) SelectCommand property stores SQL SELECT statement InsertCommand property stores SQL INSERT statement that will insert a row into a database table UpdateCommand property stores a SQL UPDATE statement to update the contents of an existing row DeleteCommand property stores a SQL DELETE statement that will remove a row or rows

Slide 54 OleDbDataAdapter (Methods) Fill method uses an OleDbConnection to retrieve database records Records are loaded into a DataSet Update method examines the DataSet for any added, changed, or deleted records Changes are recorded to DataSet Call AcceptChanges method on DataSet to synchronize DataSet and database

Slide 55 OleDbDataAdapter (Events) FillError event fires if an error occurs while populating the DataSet RowUpdating event fires just before row is updated RowUpdated event fires just after a row in the data source is updated

Slide 56 OleDbDataAdapter Class

Slide 57 OleDbCommand Class Stores SQL statements These SQL statements are used by OleDbDataAdapter to select and update rows OleDbDataAdapter executes command automatically

Slide 58 OleDbCommand Class (Properties) CommandText property stores SQL statement that will be executed against a provider Connection property stores a reference to existing OleDbConnection object Parameters property stores a reference to a Parameters collection For each parameter in the Parameters collection, the OleDbDataAdapter dynamically fills in the data that is used to add, change, or delete a database record

Slide 59 OleDbCommand Class (Methods) ExecuteNonQuery method executes a SQL statement Statement does not return database rows ExecuteReader method creates a DataReader ExecuteScalar method executes a SELECT statement Method returns the first column of the first row retrieved by the SELECT statement Additional data is discarded and no exception will occur

Slide 60 OleDbCommand Class Example Example Private modbcmdSelect As New OleDbCommand() modbcmdSelect.CommandText = "SELECT * FROM tblNames" modbcmdSelect.Connection = modbconCurrent First statement creates an instance of the OleDbCommand class Second statement stores the SQL SELECT statement in CommandText property Finally, the Connection property is set to modbconCurrent (an existing connection)

Slide 61 SQL SELECT Statement (1) SQL SELECT statement selects one or more rows (records) from a database table or query Syntax SELECT * | fieldlist FROM tablename WHERE conditionlist ORDER BY fieldlist

Slide 62 SQL SELECT Statement (2) Syntax dissection fieldlist argument specifies the field(s) to select Commas separate field names tablename argument contains database table name WHERE conditionlist argument contains a condition used to restrict the rows selected Resembles the condition in an If statement ORDER BY fieldlist argument contains a comma-separated list to sort table data Data may be sorted in ascending or descending order

Slide 63 SQL Select Example Example SELECT * FROM tblNames ORDER BY fldLastName SELECT * FROM tblNames ORDER BY fldLastName, fldFirstName SELECT fldFirstName, fldLastName FROM tblNames

Slide 64 Filling the OleDbDataAdapter (1)

Slide 65 SQL Query Parameters Use parameterized queries to select specific records Conceptually similar to a procedure accepting one or more arguments Syntax of parameters varies from provider to provider

Slide 66 OleDbParameter Class (Properties) Properties OleDbType property maps a database type to its corresponding.NET Framework type Size property defines the number of bytes required to store the data Size is inferred for numeric types Set explicit size for String types Value property stores the current value of the parameter

Slide 67 OleDbParameter Class (Constructor) Public Sub New (name As String, datatype As OleDbType, size As Integer, srccolumn As String) name argument contains the name of the parameter datatype argument contains a value that defines the data type of the argument size argument contains the maximum size of the data srccolumn argument contains the name of the column in the underlying DataTable

Slide 68 Recording DataSet Changes (1) Explicitly record any changes back to the database using the TableAdapter The following members are used to record changes back to the database The Update method of the TableAdapter records the changes made to the DataTable(s ) in a DataSet The RowState property marks whether a particular DataRow was added, changed, or deleted