Download The Selection Structure

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Oracle Database wikipedia , lookup

Tandem Computers wikipedia , lookup

Microsoft Access wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Team Foundation Server wikipedia , lookup

Database wikipedia , lookup

Functional Database Model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Relational model wikipedia , lookup

Clusterpoint wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Database model wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Transcript
Database Programming with ADO.NET
Kashef Mughal
1
Last Week
 We looked at the following:
 OleDbConnection - active connection to the
database for an OLEDB provider
 DataSet - subset of the database, can be
updateable
 OleDbDataAdapter - data bridge between the
OleDbConnection and the DataSet for an OLEDB
provider
 OleDbCommand - SQL command that is executed
against the database
2
This Week
 We are going to work with the following:
 SqlConnection - active connection to the SQL
Server database - carries the connection info
 SqlDataAdapter - data bridge between the
SqlConnection and the DataSet for a SQL Server
database
 SqlCommand - SQL command that is executed
against the database which in this case is SQL
 Why different objects for SQL Server? These are
optimized for retrieving data from SQL Server
3
A few thing about SQL Server
 Enterprise database from Microsoft
 Comes in versions 7, 2000 and YUKON (not out
yet)
 Think of SQL Server as Access on steroids
 Enterprise Manager is the tool of choice for SQL
Server administration
 Query Analyzer is the tool of choice for testing
queries and SQL code
 Go ahead and open Enterprise Manager from
Start - Program Files - Microsoft SQL Server Enterprise Manager
4
Enterprise Manager







Expand SQL Server Group
Expand your Server
Expand Database
Expand Northwind
Expand pubs
Select tables
Right click on Authors table and select Return all
rows
5
Query Builder in EM
 Click on the Show/Hide Diagram pane - Second
Tool Bar button
 Click on the Show/Hide Grid pane - Third Tool Bar
button
 Click on the Show/Hide SQL pane - Fourth Tool
Bar button
 Does this look familiar ?
 You can use this to build your SQL and then
paste it in VB.NET
6
Connection String parameters





Server - machine name
Database - e.g. Northwind
uid - username
pwd - password
Integrated Security - set to true if using Windows
Authentication
7
Back to VB.NET
 sqlCommand represents a SQL command that
can be executed against the Database
 Last week we used SELECT command
 Connection property of sqlCommand represents
the connection to the database
 CommandText property of sqlCommand is the
actual SQL command - Remember that this is a
string so you will have to use double quotes
 Parameter Collection is used with parameters
 ExecuteNonQuery method with execute the SQL
8
sqlDataAdapter
 sqlDataAdapter is similar to OleDbDataAdapter in
that it is a bridge between db and Data Set
 SelectCommand property is used to specify the
SQL for sqlDataAdapter
 Fill is the method used to populate a Data Set
using sqlDataAdapter
9
Data View object
 Works with the Data Set object
 Difference lies in the fact that Data View can be
used for sorting and filtering data
 Sort property will sort the data
 RowFilter property is used to return only data
with a specific criteria - similar to WHERE clause
10
Exercises




Try the following ones
Page 637
Page 641
Take a break when finished
11
The Server Explorer Window
 The Server Explorer can help you quickly create data
driven applications as well as allow you to create
SQL databases.
 The Server Explorer has two nodes at the top: Data
Connections and Servers.
 The Data Connections node lists the databases that
you've created a connection to using the data
adapter wizard. The Servers node lists the db servers
available to you.
12
Server Explorer Screen Shot
13
Advantages of Server Explorer
 Database Administration - You can not only view
the objects but can create new ones - You may
not have access to Enterprise Manager and can
use this tool instead
 Can create multiple connections from the same
window
 Monitor events and counters on your machine or
other servers
 Minimize the code you need to write as shown in
the next section
14
Advantages of Server Explorer - Part 2
 We will be using pubs database on the SQL
Server
 Start a new Project in Vb.NEt
 Drag the authors table from the Server explorer to
the form
 Notice it created a connection and sql adapter
 Right click on sqldataadapter1 and Preview Data
 Right click and select Generate DataSet (New)
 Add a Data Grid to the form and set properties
 Add the code to the Form Load event
15
DATA FORM WIZARD
 The data form wizard allows you to quickly create
a data bound form complete with the appropriate
ADO.NET objects and bound controls.
 To use the wizard add a new item to your project
by right clicking on the application name and
choosing Add-->Add New Item
 This will start the wizard
 Pick new data set option, call it myDS - Next
 Use existing SQL connection - Next
16
DATA FORM WIZARD - Part 2
 Select the employee table - Next
 Make sure all the fields are selected - Next
 How do you want to display data - Pick single
record - Leave all the options check and select
Finish
 Wow - You are done
 Make sure you have this DataForm1 selected as
default
 Run the bad boy!
17
A few more terms
 Data Binding is the term used when you are using
bound data control like a data grid
 Binding Context object manages all the bindings
of the controls on a form
 It does this my managing a collection of
currencymanager objects
 Currency Manager is responsible for keep data
consistent between objects and data source
18
Exercises






Try the following ones
Page 647
Page 659
Page 661
Take a break when finished
Remember next week is Final
19
Final




Chapter 8-16 minus Chapter 13
In-class material
Open Book, open notes
100 questions






true/false
multiple choice
a few from the midterm
200 points
2 hours
Grades right now
20