ADO.NET - ASP.NET (MCQ) questions and answers

Here, you can read ADO.NET multiple choice questions and answers with explanation.

1)   If you are using the DataSet and you have to display the data in sorted order what will you do?
- Published on 19 Oct 15

a. Use Sort method of DataTable
b. Use Sort method of DataSet
c. Use DataViev object with each sort
d. Use datapaging and sort the data.
Answer  Explanation 

ANSWER: Use DataViev object with each sort

Explanation:
DataView.Sortproperty allow you to sort data. Using a DataView, you can show the data in a table with different sort orders.

Example.
In this example our table name is StudentMaster.
public partial class Default5 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("provide connection string");
SqlDataAdapter da;
protected void Page_Load(object sender, EventArgs e)
{
string query = "select * from StudentMaster";
da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataView dv = new DataView();
dv = ds.Tables[0].DefaultView;
dv.Sort = "studName";
DataTabledt = dv.Table;
GridView1.DataSource = dt;
GridView1.DataBind();
}
}


2)   Which of the following is true?
- Published on 19 Oct 15

a. DataTable object contain DataRow and DataColoumn objects
b. DataSet and DataTable can be binary serialized
c. DataSet and DataTable can be XML serialized
d. All of the above
Answer  Explanation 

ANSWER: All of the above

Explanation:
A DataTable is an in-memory representation of a single database table that contains DataRow and DataColoumn objects.
Serialization is the process of converting an object into a stream of bytes so you can store or transmit the object. Only those objects can be serialized those have SerializableAttribute.
There are two types of serialization binary and XML serialization.


3)   How do you determine the actual SQL data type of a SqlParameter (the type expected by the SQL Server)?
- Published on 19 Oct 15

a. It is the .NET Framework data type in your application that the parameter represents.
b. It is the type of column or data in SQL Server that the command expects.
c. It is the type of column in a DataTablethat it represents.
d. It is any type defined in the SqlDbDataTypeenumeration.
Answer  Explanation 

ANSWER: It is the type of column or data in SQL Server that the command expects.

Explanation:
No explanation is available for this question!


4)   What are the three primary kinds of parameters?
- Published on 19 Oct 15

a. Input, Integer, String
b. Integer, String, DateTime
c. int, varchar, nvarchar
d. Input, Output, InputOutput
Answer  Explanation 

ANSWER: Input, Output, InputOutput

Explanation:
There are three types of parameters that you can use in a .NET Framework and those are Input, Output, InputOutput .
Parameters are like variables that you can use to pass and return values between your application and a database. The types of parameters are defined by SqlDbTypeenumeration. It contains a list of the types available in SQL Server. These parameter values are pass to SQL statements and stored procedures. SQL Server uses the @ symbol as a prefix to denote parameters.
Parameters are Input parameters by default. You can change its direction by using ParameterDirection property.

Example:
SqlParameterparaObj = new SqlParameter();
paraObj.ParameterName = "@TotalCost";
paraObj.SqlDbType = SqlDbType.Money;


5)   When would you typically use an Input parameter?

1. When the parameter value is created based on user input
2. When the parameter is used to send data from the application to the database
3. When the command is set to execute a statement with a WHERE clause
4. When the parameter value is passed to an INSERT statement

- Published on 19 Oct 15

a. 1, 2
b. 1, 2, 3
c. 2, 3
d. 1, 4
Answer  Explanation 

ANSWER: 2, 3

Explanation:
Input parameter is used to send data from the application to the database. You can also use input parameter in where clause. By default the parameter direction is input type. Parameters are created by using Parameter class.


6)   How do you execute multiple SQL statements using a DataReader?
- Published on 19 Oct 15

a. Call the ExecuteReadermethod of two Command objects and assign the results tothe same instance of a DataReader.
b. Call the ExecuteReadermethod of a single Command object twice.
c. Set the Command.CommandTextproperty to multiple SQL statements delimited by a semicolon.
d. Set the Command.CommandTypeproperty to multiple result sets.
Answer  Explanation 

ANSWER: Set the Command.CommandTextproperty to multiple SQL statements delimited by a semicolon.

Explanation:
You can execute more than one SQL statements delimited by a semicolon.
For this you have to set the CommandText property of a Command object to multipleSQL statements separated by semicolons (;). After calling the ExecuteReader method, theDataReader will hold the number of result sets equal to the number of SQL statements executed.

Example:
String sqlQuery = ”select * from table1; select * from table2”;
SqlConnection con = new SqlConnection(connectionString);
SqlCommandcmd = new SqlCommand ();
Con.Open();
SqlDataReaderdr = cmd.ExecuteReader();

While(dr.read())
{
// Process the table1
}
Dr.NextResult();

While(dr.read())
{
// Process the table2

}


7)   What should you do to access the returned tabular data after starting execution of a command that runs asynchronously? (Choose all that apply.)

1. Call the EndExecuteNonQuerymethod.
2. Call the EndExecuteReadermethod.
3. Wait for the StatementCompletedevent to fire and iterate through the DataReader.
4. Wait for the StatementCompletedevent to fire, call the EndExecuteReadermethod, and then iterate through the DataReader.

- Published on 19 Oct 15

a. 1, 2
b. 1, 2, 3
c. 2, 3
d. 2, 4
Answer  Explanation 

ANSWER: 2, 4

Explanation:
No explanation is available for this question!


8)   What are the Command object property settings to execute a stored procedure?

1. CommandType = Text, CommandText = stored procedure name
2. CommandType= Text, CommandText = SQL syntax to execute the stored
procedure
3. CommandType = StoredProcedure, CommandText = SQL syntax to execute the
stored procedure
4. CommandType = StoredProcedure, CommandText = stored procedure name

- Published on 19 Oct 15

a. 1, 2
b. 1, 2, 3
c. 2, 4
d. 1, 4
Answer  Explanation 

ANSWER: 2, 4

Explanation:
You can execute stored procedure by using Command object.
SqlCommandcmd = new SqlCommand();
cmd.Connection = ConnectionString;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "stored procedure name ";


9)   What is the connection string’s key / value pair for using WindowsAuthentication in SQLServer 2000 and SQL Server 2005?
- Published on 19 Oct 15

a. 1, 2
b. 1, 2, 3
c. 2, 3
d. 1, 4
Answer  Explanation 

ANSWER: 2, 3

Explanation:
You can provide yes, no, true, SSPI and false value to Integrated Security property of connection string according to the requirement. If Integrated Security= truethen current Windows account credentials are used for authentication. SSPI is equivalent to specifying True.


10)   What property contains the actual error message returned by SQL Server?

1. SqlException.Source
2. SqlException.Message
3. SqlError.Class
4. SqlError.Message

- Published on 19 Oct 15

a. 1, 2
b. 1, 2, 3
c. 1, 3
d. 2, 4
Answer  Explanation 

ANSWER: 2, 4

Explanation:
SqlException.Message and SqlError.Messageproperty contains the actual error message returned by SQL Server.


1 2 3 4 5 6