wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C#_ADO.NET

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which class is used to establish a connection with a SQL Server database in ADO.NET?

A. SqlCommand
B. SqlDataReader
C. SqlConnection
D. SqlAdapter

a)

A

b)

B

c)

C

d)

D

2.

Which part of the connection string specifies the database name?

A. Data Source
B. Initial Catalog
C. Integrated Security
D. User ID

a)

A

b)

B

c)

C

d)

D

3.

Which method is used to open a database connection?

A. Connect()
B. Start()
C. Open()
D. Begin()

a)

A

b)

B

c)

C

d)

D

4.

Which object is responsible for executing SQL queries in ADO.NET?

A. SqlConnection
B. SqlCommand
C. SqlDataAdapter
D. SqlDataReader

a)

A

b)

B

c)

C

d)

D

5.

Which method is most suitable for executing an INSERT, UPDATE, or DELETE statement?

A. ExecuteReader()
B. ExecuteScalar()
C. ExecuteNonQuery()
D. ExecuteTable()

a)

A

b)

B

c)

C

d)

D

6.

What happens if SqlConnection.Open() is called when the connection is already open?

A. Connection reopens without issue
B. Compile-time error
C. InvalidOperationException
D. Connection is closed automatically

a)

A

b)

B

c)

C

d)

D

7.

Which sequence correctly represents the query execution process in ADO.NET?

A. SqlCommand → SqlConnection → Execute
B. SqlConnection → SqlCommand → Execute
C. Execute → SqlCommand → SqlConnection
D. SqlDataReader → SqlCommand → SqlConnection

a)

A

b)

B

c)

C

d)

D

8.

Which scenario is MOST appropriate for using ExecuteReader()?

A. Retrieving a single aggregate value
B. Executing a DELETE statement
C. Reading multiple rows from a SELECT query
D. Executing stored procedures without output

a)

A

b)

B

c)

C

d)

D

9.

In an ADO.NET program, where should SqlConnection.Close() be placed to ensure the connection is closed even if an exception occurs?

A. Inside try block
B. Inside catch block
C. Inside finally block
D. Outside exception handling

a)

A

b)

B

c)

C

d)

D

10.

SqlConnection con = new SqlConnection(connStr);

// Missing line

SqlCommand cmd = new SqlCommand("SELECT * FROM Student", con);

A. con.Open();

B. con.Start();

C. con.Connect();

D. con.Begin();

a)

A

b)

B

c)

C

d)

D

11.

SqlCommand cmd = new SqlCommand(

"INSERT INTO Student VALUES(1,'Arun')", con);

// Missing line

A. cmd.ExecuteReader();

B. cmd.ExecuteScalar();

C. cmd.ExecuteNonQuery();

D. cmd.Execute();

a)

A

b)

B

c)

C

d)

D

12.

string connStr =

"Data Source=.;_____ = StudentDB;Integrated Security=True";

A. Database

B. Initial Catalog

C. Catalog

D. DBName

a)

A

b)

B

c)

C

d)

D

13.

SqlCommand cmd = new SqlCommand(

"SELECT * FROM Student", con);

// Missing line

A. cmd.ExecuteNonQuery();

B. SqlDataReader dr = cmd.ExecuteReader();

C. int x = cmd.ExecuteScalar();

D. cmd.Run();

a)

A

b)

B

c)

C

d)

D

14.

SqlConnection con = new SqlConnection(connStr);

SqlCommand cmd = new SqlCommand(

"INSERT INTO Student VALUES(1,'A')", con);

cmd.ExecuteNonQuery();

What is the issue?

A. SqlCommand missing

B. ExecuteNonQuery() invalid

C. Wrong SQL syntax

D. Connection not opened

a)

A

b)

B

c)

C

d)

D

15.

SqlCommand cmd = new SqlCommand(

"INSERT INTO Student VALUES(1,'A')", con);

int x = (int)cmd.ExecuteScalar();

What is wrong?

A. SQL syntax error

B. ExecuteScalar used for INSERT

C. Connection not opened

D. Casting error

a)

A

b)

B

c)

C

d)

D