ADO.NET Flashcards Preview

Cert IV Programming > ADO.NET > Flashcards

Flashcards in ADO.NET Deck (27):
1

What is a data provider? (3)

  • a set of libraries that are used to communicate with a data source
  • you can write your own data provider or use the pre-arranged ones, e.g. SQL Server
  • choose provider based on database type you are connecting to

2

What data providers is ADO.NET working with? (4)

SQL

Oracle

ODBC

OleDb

3

What is the namespace for SQL and what database is it connecting to?

System.Data.SqlClient

MS SQL Server

4

What is the namespace for Oracle and what database is it connecting to?

System.Data.OracleClient

Oracle

5

What is the namespace for ODBC and what database is it connecting to? (3)

System.Data.ODBC

  • used for interacting with Normally Older Databases
  • can be used as a generic provider (not as efficient or as many features as specific providers)

6

What is the namespace for OleDb and what database is it connecting to? 

System.Data.OleDb

Access, Excel

7

What common inheritance do all data providers share?

System.Data.Common

8

Which classes does System.Data.Common always contain? (4)

DBConnection

DBCommand

DBDataReader

DBParameter

9

What does the DBConnection class do?

  • it's the actual connection to the data source

10

What is the purpose of the DBCommand class?

  • used for executing SQL commands, such as SELECT queries against the data source

11

What does the DBDataReader class do?

  • reads a forward-only stream of rows from a data source, and the rows can be accessed one at a time

12

What is the DBParameter class used for?

  • is used with parameters in your sqlcommands to create dynamic queries that can change by supplying different values for the parameters

13

List the common steps to connect to a database? (5)

  1. Select the SQL provider
  2. Create a connection object
  3. Create a command object
  4. Execute the command
  5. Handle the results

14

Why do you have to create a connection object to connect to a database? (3)

  • to interact with a database, you must have a connection to it
  • the connection helps identify the database server, the database name, user name, password and other parameters that are required for connecting to the data base
  • is used by command objects so they will know which database to execute the command on

15

What are the steps required to open a SQL connection? (5)

  1. Instantiate the SqlConnection.
  2. Open the connection
  3. Pass the connection to other ADO.NET objects
  4. Perform database operations with the other ADO.NET objects
  5. Close the connection

16

Why do you have to create a Command object to open a database connection? (3)

  • helps you specify the actions you want to occur
  • use it to send SQL statements to the database
  • uses a connection object to figure out which database to communicate with

17

What are the 3 main methods of SqlCommand and what do they do?

ExecuteNonQuery – used to modify data via inserts, updates and deletes
ExecuteReader – executes the query and reads the returned results
ExecuteScalar – used to get a single returned value

18

What are the most commonly used properties of SqlCommand? (4)

CommandType

CommandText

Connection

Parameters

19

What is the CommandType of SqlCommand?

  • an enum that select which type of command to execute: Text (default), TableDirect or StoredProcedure.

20

What does the SqlCommand property CommandText do?

  • a string that can either define, the query or the related stored procedure

21

What does the SqlCommand Connection property do?

  • a connection object the command uses to connect to the database

22

What does the SqlCommand Parameters property do?

  • are parameters we pass with our query, to allow for dynamic queries

23

Give the 2 most used constructors in SqlCommand? (4)

SqlCommand();

SqlCommand("Select * From TableName", conn);

  • first parameter is the CommandText property
  • 2nd parameter is the connection object instance

24

What is the SqlDataReader for? (4)

  • many data operations require that you only get a stream of data for reading
  • allows you to obtain the results of a SELECT statement from a command object
  • for performance reasons, the data returned from a data reader is a fast forward-only stream of data
  • you can only pull the data from the stream in a sequential manner

25

What is the most important method of SqlDataReader?

Read - advances to the next row to be read

26

What is the most important property of SqlDataReader?

HasRows - is a boolean value that tells you if the data reader has rows or not

27