ADO.NET Flashcards

1
Q

What is a data provider? (3)

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

SQL

Oracle

ODBC

OleDb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

System.Data.SqlClient

MS SQL Server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

System.Data.OracleClient

Oracle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

System.Data.OleDb

Access, Excel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What common inheritance do all data providers share?

A

System.Data.Common

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

DBConnection

DBCommand

DBDataReader

DBParameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the DBConnection class do?

A
  • it’s the actual connection to the data source
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of the DBCommand class?

A
  • used for executing SQL commands, such as SELECT queries against the data source
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the DBDataReader class do?

A
  • reads a forward-only stream of rows from a data source, and the rows can be accessed one at a time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the DBParameter class used for?

A
  • is used with parameters in your sqlcommands to create dynamic queries that can change by supplying different values for the parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A
  1. Select the SQL provider
  2. Create a connection object
  3. Create a command object
  4. Execute the command
  5. Handle the results
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A
  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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A
  • 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
Q

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

A

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
Q

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

A

CommandType

CommandText

Connection

Parameters

19
Q

What is the CommandType of SqlCommand?

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

What does the SqlCommand property CommandText do?

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

What does the SqlCommand Connection property do?

A
  • a connection object the command uses to connect to the database
22
Q

What does the SqlCommand Parameters property do?

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

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

A

SqlCommand();

SqlCommand(“Select * From TableName”, conn);

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

What is the SqlDataReader for? (4)

A
  • 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
Q

What is the most important method of SqlDataReader?

A

Read - advances to the next row to be read

26
Q

What is the most important property of SqlDataReader?

A

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

27
Q
A