ADO.NET MCQs

ADO.NET MCQs

These ADO.NET multiple-choice questions and their answers will help you strengthen your grip on the subject of ADO.NET. You can prepare for an upcoming exam or job interview with these 50+ ADO.NET MCQs.
So scroll down and start answering.

1: The WriteXml method of a DataSet writes the data of the DataSet in an XML file. WriteXml accepts a parameter for the different types of destinations. Which of the following is an invalid type for the destination?

A.   String

B.   System.IO.Stream

C.   System.IO.TextStream

D.   System.IO.TextWriter

E.   System.Xml.XmlWriter

2: ADO.NET is known for disconnected data extraction. Which of the following does not use the disconnected mechanism while extracting data from the database?

A.   DataAdapter

B.   DataReader

C.   DataSet

D.   None of the above

3: You have following data table structure:
Sales
-----------
SalemanId
OrderId
Price
How will you calculate the total amount generated by a salesman (with SalemanID =2201) if the name of DataTable is "DatTab?"

A.   DatTab.Calculate("Sum(Price)", "SalemanID = 2201")

B.   DatTab.Compute("Sum(Price)", "SalemanID = 2201")

C.   DatTab.Calculate("SalemanId = 2201","Sum(Price)")

D.   DatTab.Compute("SalemanId = 2201","Sum(Price)")

4:

You have a data table named "DTable." You are writing a sub routine to validate the changes made by the user. Which of the following would you use to get the changed table data?

A.   DTable.GetChanges(DataRowState.Modified)

B.   DTable.GetChanges(DataRowsModified)

C.   DTable.TableChanges(DataRowState.Modified)

D.   DTable.TableChanges(DataRowsModified)

5: You have created an SqlCommand object as shown below by passing the sql query and the connection object.Dim cmd as New SqlCommand("Select CategoryID, CategoryName FROM Categories", con)Which of the following methods would be used by you to get data?

A.   cmd.ExecuteScalar()

B.   cmd.ExecuteNonQuery()

C.   cmd.ExecuteReader()

D.   cmd.Execute() 

6: You use a Command object to retrieve employee names from the employee table in the database. Which of the following will be returned when this command is executed using the ExecuteReader method?

A.   DataRow

B.   DataSet

C.   DataTable

D.   DataReader 

7: You have to retrieve the details of some members from the "Member" table. The data reader is executed to get the values. Which of the following helps go through the results?

A.   DataReader.Next

B.   DataReader.Move

C.   DataReader.Read

D.   DataReader.MoveNext

8: You have two parent and child data tables named "DTOrder" and "DTOrderDetail" respectively. Both are stored in a data set named "DS." How will you make a relation "DTOrder2DTOrderDetail" between the two, using "OrderId" as primary key?

A.   DS.Relation.Add(DS.Tables["DTOrder"].Columns["OrderId"], DS.Tables["DTOrderDetail"].Columns["OrderId"]), 2.DS.Relations.Add("DTOrder2DTOrderDetail",

B.   DS.Relations.Add(DS.Tables["DTOrder"].Columns["OrderId"], DS.Tables["DTOrderDetail"].Columns["OrderId"]), 3.DS.Relation.Add("DTOrder2DTOrderDetail",

C.   DS.Relation.Add(DS.Tables["DTOrderDetail"].Columns["OrderId"], DS.Tables["DTOrder"].Columns["OrderId"]), 4.DS.Relations.Add("DTOrder2DTOrderDetail",

D.   DS.Relations.Add(DS.Tables["DTOrderDetail"].Columns["OrderId"], DS.Tables["DTOrder"].Columns["OrderId"])">

9: Which of the following was not among the main design goals behind ADO NET?

A.   To provide seamless support for XML

B.   To support COM directly

C.   To provide an expandable and scalable data access architecture for the revolutionary n-tier programming model

D.   To extend the current capabilities of ADO 

10: Which of the following options should you use to copy the edited rows from a dataset called ProductInfo into another dataset called Product Changes?

A.   productChanges = productInfo.GetChanges(DataRowState.Detached)

B.   productChanges = productInfo.GetChanges()

C.   productChanges.Merge(productInfo, true)

D.   productChanges.Merge(productInfo, false) 

11: Which of the following command types are provided by an oledb and sql provider?

A.   StoredProcedure,Text, TableDirect

B.   StoredProcedure,Query, TableDirect

C.   Procedure,Text,Table,Query

D.   Procedure,Query, TableDirect

12: You have defined an SQL Command object named "sqlComm" to run a stored procedure. The OUT parameter is as follows:
Dim pm2 As New SqlParameter("@Amount," SqlDbType.Money)
How will you add the OUT parameter named pm2 to the command object?

A.   sqlComm.Parameters.Add(pm2)

B.   sqlComm.Parameters.Add(pm2).Mode = ParameterMode.Output

C.   sqlComm.Parameters.Add(pm2).Direction = ParameterDirection.Output

D.   sqlComm.Parameters.Add(pm2).Direction = ParameterDirection.ReturnValue 

13: Read the following statements:
DataRow oDetailsRow = oDS.Table["OrderDetails"].NewRow();
oDetailsRow["ProductId"] = 1;
oDetailsRow["ProductName"] = "Product 1";
What is wrong with this code?

A.   Table is not a collection of DataSet

B.   Name of the column can not be passed in the Columns collection

C.   NewRow is not a method of the Tables collection

D.   None of the above 

14: Which of the following implements IDataReader interface?

A.   SqlDataReader

B.   OleDbDataReader

C.   OracleDataReader

D.   ODBCDataReader

E.   All of the above

15: You have defined a command named "cmdA" and an open connection named "con". You created a new transaction:
Dim trans As SqlClient.SqlTransaction = Nothing
How will you assign the command to the transaction and begin the transaction?

A.   cmdA.Transaction = trans
cmdA.ExecuteNonQuery()

B.   trans.BeginTransaction()
cmdA.Transaction = trans
cmdA.ExecuteNonQuery() 

C.   trans = con.BeginTransaction()
cmdA.Transaction = trans
cmdA.ExecuteNonQuery()

D.   trans = con.OpenTransaction()
cmdA.Transaction(trans)
cmdA.ExecuteNonQuery() 

16: How can you make a data reader close connection automatically?

A.   command.ExecuteReader()

B.   command.ExecuteReader(CommandBehavior.Default)

C.   command.ExecuteReader(CommandBehavior.CloseConnection)

D.   command.ExecuteReader(CommandBehavior.SingleRequest)

17: Read the following statements: OleDbDataAdapter oOrderDetailsDataAdapter; OleDbCommandBuilder oOrderDetailsCmdBuilder = New OleDbCommandBuilder(oOrderDetailsDataAdapter); oOrderDetailsDataAdapter.FillSchema(oDS, SchemaType.Source); What is wrong in this code?

A.   The parameters are incorrect for the FillSchema method

B.   OleDbCommandBuilder has no constructor

C.   oOrderDetailsDataAdapter has not been instantiated

D.   None of the above

18: Which of the following statements are correct? (a)SQL statements are generally faster than stored procedures (b)The database engine works out the execution plan for SQL statements at run time

A.   Only (a) is true

B.   Only (b) is true

C.   Both (a) and (b) are true

D.   Both (a) and (b) are false

19: Asynchronous execution is supported in ADO.NET 2.0 for ExecuteReader, ExecuteScalar, and ExecuteNonQuery.

A.   True

B.   False 

20: In .Net application, you have to update 40 records together in the update query. Previous versions of ADO.NET would be making 40 calls to database. Which of the following parameters is set to 40 with version 2.0?

A.   DataAdapter.UpdateBatchSize

B.   DataAdapter.UpdateSize

C.   DataAdapter.BatchSize

D.   DataAdapter.BatchRecordSize 

21: Read the following statement: DataTable.Merge (DataTable, Boolean) What is the boolean parameter?

A.   This is an out parameter and returns the status of merging

B.   Determines whether duplicate data should be removed

C.   Indicates whether to preserve changes in the current DataTable

D.   None of the above 

22: You have to update some values in the database. Which of the following methods would you execute on a command object named "cmdUpdate?"

A.   cmdUpdate.ExecuteScalar()

B.   cmdUpdate.ExecuteNonQuery()

C.   cmdUpdate.ExecuteReader()

D.   cmdUpdate.Execute()

E.   ExecuteXmlReader() 

23: You have a table named "FirstQTR" and want to create another table "SecondQTR" which is exactly the same as "FirstQTR", including DataTable schema and constraints. Which of the following methods fulfills the requirement?

A.   Copy

B.   Clone

C.   Duplicate

D.   Equals 

24: Premium Finance Corp is involved in the savings business with branches all over the country. They provide flexible schemes which can be designed according the clients requirements. A dataset maintains all schemes in separate tables. You want to show all the schemes in different datagrids which should be created in the same sequence as the tables are in dataset. Which one is the most suitable method in the current scenario?

A.   Write a loop for the tables() collection and call CreateDataReader for each table and bind with a dynamically generated datagrid

B.   Call GetXMLSchema, create an XML file and then bind with a dynamically generated datagrid

C.   Create datagrids for each table and bind with the relevant table

D.   None of the above 

25: Premium Corporation is running an insurance business. They are planning to create a website to automate the business. An aspx page, Sales.aspx will display the sales generated by an executive. The sales will be displayed in a datagrid. The executives can change some fields like the address or phone numbers of clients, and they can add new sales also. Which of the following will you prefer to use for this?

A.   DataReader

B.   DataAdapter

C.   Command object's ExecuteNonQuery

D.   DataReader with Command object's ExecuteNonQuery

E.   None of the above

26: Which of the following is not correct with regard to DataReader and DataSet?

A.   DataReader reads one row from the database

B.   DataSet gets complete set of data from the database

C.   DataReader can only get its data from a data source through a managed provider

D.   DataReader closes its connection automatically 

27: You have got a supplier data table named "DTSupp." To display records specifically with sorting, you employed a dataview as follows: Dim DataViewSupp As DataView = DTSupp.DefaultView What is the "DataViewSupp" table view by default?

A.   It is unfiltered and contains references to the records included in the table

B.   It is filtered on ID column and contains references to the records included in the table

C.   It is unfiltered and does not contain references to the records included in the table

D.   It is filtered on ID column and does not contain references to the records included in the table 

28: You are developing a website that has four layers. The layers are: user interface (web pages), business objects, data objects, and the database. You want to pass data from the database to controls on a web form. What should you do?

A.   Populate the data objects with data from the database. Populate the controls with values retrieved from the data objects

B.   Populate the business objects with data from the database. Populate the controls with values retrieved from the business objects

C.   Populate the data objects with data from the database. Populate the business objects with data from the data objects. Populate the controls with values retrieved from the business objects

D.   Bind the controls directly to the database 

29: Read the following statement: DataTable.Select (String, String) Here, the first parameter accepts a criteria for filtration, what does the second parameter do?

A.   Specifies the sort order

B.   Accepts another criteria

C.   Specifies the column name which should be searched

D.   Header of output

30: Which of the following methods ensures optimum use of Connection Pooling?

A.   By using current user's login for authentication and getting the connection

B.   By using a common account login for authentication and getting the connection

C.   By using a current user's login for authentication and using 'common account login' for getting the connection

D.   None of the above 

31: Read the following statements: Dim dr As DataRow Dim objCustReader As Data.SqlClient.SqlDataReader Dim dtCustomers As DataTable With dtCustomers.Columns.Add(New DataColumn("Customer ID")) End With What is wrong in above code?

A.   Add is not a method of the Columns collection

B.   Column collection should be used instead of columns collection

C.   The Data Type of the column is a required parameter of 'Add' method

D.   None of the above

32: Read the following statements: DataRow oDetailsRow = oDS.Tables["OrderDetails"].Row(); oDetailsRow["ProductId"] = 1; oDetailsRow["ProductName"] = "Product 1"; What is wrong in this code?

A.   The name of the table can not be passed in the Tables collection

B.   The name of the column can not be passed in the Columns collection

C.   Row is not a method of the Tables collection

D.   None of the above 

33: Which of the following options is ideally suited for managing database connections?

A.   Pass the open connection objects between the methods

B.   Close the connection as soon as database operation is done

C.   Open a global connection and keep on using it without reopening

D.   Within a transaction, a connection should be closed in each method and reopened in the other

34: Which of the following is not associated with the command  object in ADO.NET 2.0?

A.   cmd.ExecuteScalar()

B.   cmd.ExecutePageReader()

C.   cmd.ExecuteReader()

D.   cmd.ExecuteXmlReader()

E.   cmd.Execute() 

35: Which of the following are used for database connections between SQL Server and ASP.NET?

A.   SqlInfoMessageEvent

B.   SqlParameterCollection

C.   SqlRowUpdatingEvent

D.   SqlClientPermissionAttribute 

36: Which of the following statements is incorrect with regard to ADO?

A.   ADO uses recordset whereas ADO.NET uses dataset

B.   ADO navigation approach is non-sequential, whereas in ADO.NET it's sequential

C.   Disconnected access in ADO has to be coded explicitly, whereas ADO.NET handles it with the adapter

D.   ADO offers hierarchical RecordSet for relating multiple tables, whereas ADO.NET provides data relations 

37: Which of the following is not a member of the CommandType enumeration?

A.   Table

B.   storedProcedure

C.   TableDirect

D.   Text 

38: Which of the following statements is incorrect with regard to a CommandBuilder object?

A.   It creates insert, update, and delete queries on the fly

B.   It creates efficient queries in terms of performance

C.   A unique column must be selected as a part of the select query

D.   It can't work with queries having joins 

39: Which of the following statements with regard to DataSet is correct?

A.   A DataSet can derive data from a database

B.   A DataSet can derive data from an xml file

C.   A DataSet can derive data from both xml file and a database

D.   A DataSet can be used to view data only 

E.   Datasets store data in a disconnected cache

40: When users edit data in your program, the code runs to completion without error, but no data changes appear in the database. You test the update query and the connection string that you are passing to the procedure, and they both work correctly. What changes do you need to make to your code to ensure that data changes appear in the database?

A.   Add the following two lines of code before calling the Update method: Dim cb As New OleDb.OleDbCommandBuilder(da) cb.GetUpdateCommand() 

B.   Add the following line of code before calling the Update method: da.UpdateCommand.Connection.Open() 

C.   Delete this line of code: dataTable.AcceptChanges() 

D.   Delete this line of code: da.Dispose() 

41: We are iterating through the results received in a data reader named "DReaderOrder," which is created by using connection "SqlCon." In between, we need to retrieve some more values from the database, so we executed another command using "SqlCon," to get the results in another data reader "DReaderProduct." What will happen if we use ADO.NET 1.1?

A.   First data reader will immediately stop and new data reader starts reading

B.   First data reader will halt till the new data reader finishes reading

C.   Both will keep on reading records independent of each other

D.   We receive an exception 'Systerm.InvalidOperationException' 

42: Which of the following is not a valid member of DataAdapter?

A.   AcceptChanges

B.   acceptchangesDuringFill

C.   Container

D.   TableMappings

43: You must create a stored procedure to retrieve the following details for the given customer:

CustomerName, Address, PhoneNumber

Which of the following is an ideal choice to get the result?

A.   Return the result as dataset using data adapter

B.   Return the result as dataset using command object

C.   Return the result as three out parameters and command object

D.   All of the above

A.   sqlComm.Parameters.Add(TotalSale,Out)

B.   sqlComm.Parameters.Add(TotalSale).Mode = ParameterDirection.Output

C.   sqlComm.Parameters.Add(TotalSale).Direction =  Parameter.Output

D.   sqlComm.Parameters.Add(TotalSale).Direction = ParameterDirection.Output

45: We are iterating through the results received in a data reader named "DReaderOrder," which is created by using the connection "SqlCon." In between we need to retrieve some more values from the database, so we executed another command in the same connection to get the results in a new data reader named "DReaderProduct." What will be the result if we are using ADO.NET 2.0? (Note:Multiple Active Result Sets (MARS) is enabled in SQL Server 2005).

A.   First data reader will immediately stop and new data reader starts reading

B.   First data reader will halt till the new data reader finishes reading

C.   Both will keep on reading records independent of each other

D.   We receive an exception 'System.InvalidOperationException'

46: Which of the following is not true about CommandType.TableDirect?

A.   TableDirect is only supported by the .NET Framework Data Provider for OLE DB

B.   Multiple table access is not supported when CommandType is set to TableDirect

C.   TableDirect does not accept table as a parameter

D.   None of the above

47: You are using Visual Basic to retrieve class information from a Microsoft SQL Server database named ClassList. The database resides on a server named Neptune. Which code fragment will create a connection to this data source?

A.   Set conn = New SqlConnection; With conn ; .Provider = "SqlOleDB" ; ConnectionString ="User ID=sa;"&& "Data Source=Neptune;"&& "Initial Catalog=ClassList"

B.   Set conn = New SqlConnection; With conn ; .Provider = "Neptune" ; ConnectionString ="User ID=sa;"&& "Data Source=Neptune;"&& "Initial Catalog=ClassList"

C.   Set conn = New SqlConnection; With conn ; .Provider = "SqlOleDB" ; ConnectionString ="User ID=sa;"&& "Data Source= Neptune;"

48: You have written a function to generate a unique bill number for every new bill:1 Public Function getNewBillNo() As Integer 2 Dim cm As New SqlCommand("select max(billno) from bill", con) 3 con.Open() 4            
5      
6 End Function

You want to return "1" as new ID, if there exists no record in the database. Otherwise, the return value should be the maximum bill number plus one. What should follow in line 4, if you want to check for Null values as well?

A.   Return (IIf(IsNull(cm.ExecuteNonQuery), 1, cm.ExecuteNonQuery +1))

B.   Return (IIf(IsDBNull(cm.ExecuteScalar), 1, cm.ExecuteScalar +1 ))

C.   Return (IIf(IsNull(cm.ExecuteScalar), 1, cm.ExecuteScalar))

D.   Return (IIf(IsDBNull(cm.ExecuteNonQuery), cm.ExecuteNonQuery ,1)) 

49: PreFin101.com has a guest book which uses an XML document. Initially, an XML file is uploaded into the datatable. As records increase, the "GuestID" column should be incremented. Which properties of the column will be used to implement the auto increment functionality?

A.   AutoIncrementSeed

B.   AutoIncrementStep

C.   AutoIncrement

D.   AutoIncrementNumber

E.   AutoIncrementIndex

50: Which of the following is capable of returning multiple rows and multiple columns from the database?

A.   ExecuteReader

B.   ExecuteXmlReader

C.   Adapter.fill

D.   All of the aboveÂ