ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.

Slides:



Advertisements
Similar presentations
Introduction to Database Processing with ADO.NET.
Advertisements

VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
Visual Studio 2005 Using the DataGridView Control V. Matos Cleveland State University.
VB.NET Database Tools ISYS Net Applications OLE DB Provider OLE DB Data Source OLE DB Provider ODBC Data Source SQL Server Data Source SQL Server.Net.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
Coding ADO.NET Objects: Connection, Command, DataReader.
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.
Visual Basic Database Access BICS546. Microsoft Universal Data Access OLE DB: The OLE database protocol –Allows a program to access information in any.
VB.NET Database Tools ISYS 573. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Coding ADO.NET Objects: Connection, Command, DataReader.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS546.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
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.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
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.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
1/36 Database Programming with Visual Basic.Net and MS Access IKE Lab. Yunho Song Database Management and Analysis.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
 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.
Microsoft Visual Basic 2008 CHAPTER TWELVE Cell Phone Applications and Web Services.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
ADO.NET connections1 Connecting to SQL Server and Oracle.
 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.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
HNDIT Rapid Application Development
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
Coding ADO.NET Objects: Connection, Command, DataReader.
1 Database Programming with ADO.NET Kashef Mughal.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
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.
CIS 338: VB.NET Printing Dr. Ralph D. Westfall May, 2011.
Creating SQL Database file And Displaying a Database Table in a DataGridView.
ASP.NET Programming with C# and SQL Server First Edition
Visual Basic Database Access
Introduction to Database Processing with ADO.NET
Coding ADO.NET Objects: Connection, Command, DataReader
Introduction to Database Processing with ADO.NET
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Lecture 6 VB.Net SQL Server.
GUI Programming using Windows Form
ADO.NET Accessing Databases in VS.NET
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Introduction to VB programming
Coding ADO.NET Objects: Connection, Command, DataReader
Chapter 10 Accessing Database Files
CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009.
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
GUI Programming in Visual Studio .NET
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

ADO.NET Objects – Data Providers Dr. Ron Eaglin

Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed –Database available on local machine

Agenda Working with the Database Connection Object –ConnectionString property –Visual Creation of Connection –Code Creation of Connection –Runtime Connections

Database Connections Create a new project Windows application Name project: AdventureWorksDemo1

Using Toolbox Right click on the data icon in the toolbox Select “Choose items …” This will bring up a dialog allowing you to select all items displayed from the list of available tools.

Data “items” Select SQLConnection from List of available tools The SQLConection object Will now be in your Toolbox

Adding SQLConnection to Form Drag and drop SQLConnection Object onto Form.

SQL Connection Object Select the SQLConnection object in the form and look at the Properties dialog box. Select the ConnectionString property And select

Add Connection Select your server Select AdventureWorks database Test the connection

Add Connection ConnectionString property will fill with the text that allows the connection. ConnectionString has form Keyword=value;keyword=value;keyword=value Example: Data Source=WHITEWATER;Initial Catalog=AdventureWorks;Integrated Security=True

Adding Connection String with Code Add button to form and Change text of button Double click button for Code window

Button Code window Enter code here

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Create a new connection object of type SQLConnection Dim RuntimeConnection As New Data.SqlClient.SqlConnection ' Set the connection string RuntimeConnection.ConnectionString = "Data Source=WHITEWATER;Initial Catalog=AdventureWorks;Integrated Security=True" Try RuntimeConnection.Open() MsgBox("Connection with connection string " + RuntimeConnection.ConnectionString + " opened successfully", MsgBoxStyle.Information) Catch ex As Exception MsgBox("Connection with connection string " + RuntimeConnection.ConnectionString + " failed to open", MsgBoxStyle.Information) End Try RuntimeConnection.Close() End Sub

Test Application

Add code to test SQLConnection1 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try SqlConnection1.Open() MsgBox("Connection with connection string " + SqlConnection1.ConnectionString + " opened successfully", MsgBoxStyle.Information) Catch ex As Exception MsgBox("Connection with connection string " + SqlConnection1.ConnectionString + " failed to open", MsgBoxStyle.Information) End Try SqlConnection1.Close() End Sub

Test SQLConnection1

SQLConnection Properties ConnectionString ConnectionTimeout Database DataSource ServerVersion State

Other types of Connections SQLConnection is specific to SQl Server only ODBCConnection – any ODBC database OLEDBConnection – Any OLE DB datasource OracleConnection

Agenda Creating and using a DataCommand object Issuing Database commands using the DataCommand object.

DataCommand object DataCommand is a simple ADO.NET wrapper for a SQL Statement. Using DataCommand from design and from run-time.

Design Window SQLCommand If SQLCommand is not in your toolbox, right click and add it to your toolbox using the Choose Items… Drag and drop the SQLCommand on to your form.

SQLCommand added SQLCommand object in form

SQLCommand Properties of the SQLCommand –Connection –CommandType Text StoredProcedure TableDirect –Parameters

SQLCommand1 Properties Set Connection = SQLConnection1 Set CommandType = Text Click on … dialog on CommandText Property

Clicking on box Will bring up query Builder.

Once the query is built – it is possible to use the preview Data link in the properties window.

Runtime SQLCommand Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim rtSQLCommand As New Data.SqlClient.SqlCommand rtSQLCommand.Connection = SqlConnection1 rtSQLCommand.CommandType = CommandType.Text rtSQLCommand.CommandText = "SELECT Person.Address.* FROM Person.Address" End Sub

SQLCommand Note that running the code to create the runtime SQLCommand – does not actually do anything. We must execute the Command and also have a place for the results.

DataReader Object A DataReader is a lightweight object meant to hold the results of a SQLCommand DataReaders can be treated as a cursor to go through the DB values.

DataReader SqlConnection1.Open() Dim rtDataReader1 As Data.SqlClient.SqlDataReader rtDataReader1 = rtSQLCommand.ExecuteReader If rtDataReader1.HasRows = True Then MsgBox("The reader has found rows", MsgBoxStyle.Information) End If SqlConnection1.Close() Add this code to the previous code

Binding the Data Reader Add Listbox To Form

Add code While rtDataReader1.Read ListBox1.Items.Add(rtDataReader1.GetValue(1)) End While Add code before closing the connection, after executing the reader.

Results of Code Data from first field of DB Query is added to the list.

DataReader Methods Open code window Put cursor on the code Dim rtDataReader1 As Data.SqlClient.SqlDataReader Hit F1 Put cursor here

Help on DataReader Code examples of using Data Reader More code

Review Working with Database Connection Creating code to use database Using Command Objects Using the Data Reader Object Displaying Database Results Getting More Information on Objects