MCQs on Working with Databases | Visual Basic .NET (VB.NET)

Test your knowledge on essential database concepts in VB.NET with 30 multiple-choice questions. These questions cover ADO.NET basics, connecting to databases, executing queries, handling results, and data binding with controls.


MCQs on Working with Databases in VB.NET

ADO.NET Basics

  1. What is ADO.NET primarily used for in VB.NET?
    a) Designing user interfaces
    b) Accessing data in databases
    c) Creating network connections
    d) Handling errors
  2. Which ADO.NET component provides the connection to a database?
    a) DataReader
    b) DataSet
    c) DataAdapter
    d) SqlConnection
  3. What is the purpose of a DataSet in ADO.NET?
    a) To store data in an XML format
    b) To execute SQL commands
    c) To hold data retrieved from a database
    d) To manage database connections
  4. Which object in ADO.NET is used to execute SQL commands against a database?
    a) SqlCommand
    b) SqlConnection
    c) SqlAdapter
    d) SqlReader
  5. Which method is used to open a database connection in ADO.NET?
    a) OpenConnection()
    b) BeginTransaction()
    c) Open()
    d) ExecuteReader()

Connecting to a Database
6. How do you specify the connection string in VB.NET for SQL Server?
a) Server=localhost;Database=myDB;User Id=myUser;Password=myPass;
b) Host=myDB;Port=3306;Username=myUser;Password=myPass;
c) Connection=myDB;User=myUser;Password=myPass;
d) Connect=myDB;UserId=myUser;Pass=myPass;

  1. What does the ConnectionState.Open indicate?
    a) The database connection is closed
    b) The connection is open and ready for queries
    c) The connection is in a transaction
    d) The connection has failed
  2. Which of the following is needed to establish a connection with a database in VB.NET?
    a) A DataAdapter
    b) A valid connection string
    c) A DataSet
    d) A DataReader
  3. Which class is used to connect to a SQL Server database in ADO.NET?
    a) SqlCommand
    b) SqlDataAdapter
    c) SqlConnection
    d) SqlReader
  4. In VB.NET, how do you close an open database connection?
    a) CloseConnection()
    b) Dispose()
    c) Close()
    d) Disconnect()

Executing Queries and Handling Results
11. Which method is used to execute a query that returns rows in ADO.NET?
a) ExecuteScalar()
b) ExecuteReader()
c) ExecuteNonQuery()
d) Execute()

  1. Which method in SqlDataReader is used to move through rows in a result set?
    a) Read()
    b) Next()
    c) Move()
    d) Fetch()
  2. What does the ExecuteNonQuery() method do?
    a) Executes a query and returns a result set
    b) Executes a query and returns the number of rows affected
    c) Retrieves a single value from the database
    d) Retrieves all records from the database
  3. Which method is used to fetch a single value from the database in ADO.NET?
    a) ExecuteScalar()
    b) ExecuteReader()
    c) ExecuteNonQuery()
    d) ExecuteQuery()
  4. In ADO.NET, how do you retrieve all rows from a DataTable?
    a) Using DataSet.Select()
    b) Using SqlCommand.ExecuteReader()
    c) Using DataTable.Rows()
    d) Using DataAdapter.Fill()
  5. How do you handle exceptions when executing SQL queries in ADO.NET?
    a) Using Try-Catch blocks
    b) Using Finally blocks
    c) Using error-handling functions
    d) Using SqlErrorHandler()
  6. What is the purpose of SqlDataAdapter.Fill() method?
    a) To open a database connection
    b) To execute a query
    c) To retrieve data and populate a DataTable
    d) To fetch a single value
  7. Which object is used to retrieve results from a database as a stream of data?
    a) SqlConnection
    b) SqlCommand
    c) SqlDataReader
    d) SqlDataAdapter
  8. What type of command does ExecuteReader() execute?
    a) SELECT
    b) INSERT
    c) UPDATE
    d) DELETE
  9. What does the ExecuteScalar() method return?
    a) A dataset
    b) A single row of data
    c) A single value from the first column of the first row
    d) A DataReader

Data Binding with Controls
21. What does data binding allow in VB.NET?
a) Connecting a database to a UI control
b) Creating new database records
c) Executing database commands
d) Modifying control properties

  1. Which control is commonly used for data binding in a VB.NET application?
    a) TextBox
    b) Button
    c) DataGridView
    d) Label
  2. How do you bind a DataTable to a DataGridView?
    a) Using DataGridView.DataBind()
    b) Setting the DataGridView.DataSource property
    c) Using DataSet.Add()
    d) Using SqlCommand.Execute()
  3. What is the purpose of BindingSource in data binding?
    a) To execute SQL queries
    b) To manage the connection to the database
    c) To manage the data for binding controls
    d) To handle SQL exceptions
  4. Which method in ADO.NET is used to bind data to a ComboBox?
    a) ComboBox.Bind()
    b) ComboBox.DataSource()
    c) ComboBox.Items.Add()
    d) ComboBox.Fill()
  5. How can you update the database after editing data bound to a control?
    a) By calling Update() on the DataAdapter
    b) By setting the control’s data to null
    c) By using a TransactionManager
    d) By manually updating the database
  6. Which object in VB.NET is used to establish a connection to the database for data binding?
    a) DataAdapter
    b) SqlConnection
    c) SqlCommand
    d) SqlDataReader
  7. Which event is commonly used for handling changes in bound data in controls like TextBox?
    a) TextChanged
    b) ValueChanged
    c) DataChanged
    d) DataBinding
  8. Which property of a control allows it to display bound data?
    a) DataSource
    b) DisplayMember
    c) DataField
    d) Text
  9. What is a primary benefit of data binding in VB.NET applications?
    a) It simplifies the code needed to update UI controls
    b) It improves performance by using less memory
    c) It reduces the need for database connections
    d) It automatically executes database queries

Answer Key

QnoAnswer (Option with the text)
1b) Accessing data in databases
2d) SqlConnection
3c) To hold data retrieved from a database
4a) SqlCommand
5c) Open()
6a) Server=localhost;Database=myDB;User Id=myUser;Password=myPass;
7b) The connection is open and ready for queries
8b) A valid connection string
9c) SqlConnection
10c) Close()
11b) ExecuteReader()
12a) Read()
13b) Executes a query and returns the number of rows affected
14a) ExecuteScalar()
15d) Using DataAdapter.Fill()
16a) Using Try-Catch blocks
17c) To retrieve data and populate a DataTable
18c) SqlDataReader
19a) SELECT
20c) A single value from the first column of the first row
21a) Connecting a database to a UI control
22c) DataGridView
23b) Setting the DataGridView.DataSource property
24c) To manage the data for binding controls
25b) ComboBox.DataSource()
26a) By calling Update() on the DataAdapter
27b) SqlConnection
28a) TextChanged
29a) DataSource
30a) It simplifies the code needed to update UI controls

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top