Working with ADO.NET - ASP.NET Placement questions

Working with ADO.NET - ASP.NET Placement questions


Q.1 Choose the correct option about the Integrated Security property of connection object.

A) If Integrated Security=false then User ID, and Password must be specified in the connection string.
B) If Integrated Security=true then current Windows account credentials are used for authentication.
C) Both A and B option are correct.
D) None of the above.

View Answer / Hide Answer

ANSWER: C

Explanation:

You can provide yes, no, true, SSPI and false value to Integrated Security property according to the requirement and security of application. If Integrated Security=false then User ID, and Password must be specified in the connection string and if true then current Windows account credentials are used for authentication. SSPI is equivalent to specifying True.




Q.2 You are a Web developer for CareerRide. The data is stored in a Microsoft SQL Server 2005 database on a server named CareerPC and the Database name is TestDB. You connect to TestDB by using Windows Integrated authentication. You use a SqlConnection object to connect to the database. You need to create a connection string to TestDB in the instance of SQL Server named CareerPC. Which string should you use?

A) “Data Source= CareerPC; Database=TestDB; Integrated Security=SSP1”.
B) “Data Source= CareerPC; Initial Catalog=TestDB; Integrated Security=SSP1”.
C) “Server= CareerPC; Database=TestDB; Integrated Security=SSP1”.
D) All of the above.

View Answer / Hide Answer

ANSWER: D

Explanation:

You can write Data Source or Server or Address or Addr or Network Address to the instance of SQL Server to which to connect. To specify the database you should either use the Database or the Initial Catalog attribute.




Q.3 Which ado.net class provide disconnected environment?

A) DataReader
B) DataSet
C) Command
D) None of the above.

View Answer / Hide Answer

ANSWER: B




Q.4 Which ado.net class provide connected environment?

A) DataReader
B) DataSet
C) Command
D) None of the above.

View Answer / Hide Answer

ANSWER: A




Q.5 What are the Command Object Methods?

A) ExecuteNonQuery
B) ExecuteReader
C) ExecuteScalar
D) All of the above.

View Answer / Hide Answer

ANSWER: D

Explanation:

The common methods of command abject are as follows.

- ExecuteReader: This method works on select SQL query. It returns the DataReader object. Use DataReader read () method to retrieve the rows.

- ExecuteScalar: This method returns single value. Its return type is Object. If you call ExecuteScalar method with a SQL statement that returns rows of data, the query executes but returns only the first column of the first row returned by the query.

- ExecuteNonQuery: If you are using Insert, Update or Delete SQL statement then use this method. Its return type is Integer (The number of affected records).




Q.6 You are a Web developer for CareerRide. The data is stored in a Microsoft SQL Server 2005 database on a server named CareerPC and the Database name is TestDB. There is one GridView control on the page that you want to fill with table name Employee. Suppose that SqlConnection object is conObj and SqlCommand Object object is cmdObj. Which important properties of command object you will initialize to achieve this task?

A) cmdObj.CommandType = Text;
cmdObj.Connection = conObj;
cmdObj.CommandText = "select * from Employee";

B) cmdObj.CommandConnection = conObj;
cmdObj.CommandText = "select * from Employee";

C) cmdObj.CommandType = CommandType.Text;
cmdObj.Connection = conObj;
cmdObj.CommandText = "select * from Employee";

D) None of the above.

View Answer / Hide Answer

ANSWER: C




Q.7 If you want that SQL statement, when work with SqlCommand , should returns a Single value then which method of Command Object will be used?

A) ExecuteNonQuery
B) ExecuteReader
C) ExecuteScalar
D) All of the above.

View Answer / Hide Answer

ANSWER: C

The ExecuteScalar method executes the query, and returns the first column of the first row as the resultset returned by the query. Extra columns or rows are ignored. The ExecuteScalar method is used to retrieve a single value from a database. If SQL statements have aggregate function then this function works effectively.




Q.8 If you want that command object should returns XML data then which method of Command Object will be used?

A) getXMLData
B) getXML
C) ExecuteXMLReader
D) None of the above.

View Answer / Hide Answer

ANSWER: C




Q. 9 How do you execute multiple SQL statements using a DataReader?

A) Call the ExecuteReader method of a single Command object twice.
B) Set the Command.CommandText property to multiple SQL statements delimited by a semicolon.
C) Set the Command.CommandType property to multiple result sets.
D) None of the above.

View Answer / Hide Answer

ANSWER: B

Explanation:

Pass the multiple SQL statements in command object constructor delimited by a semicolon and iterate through the DataReader. Use DataReader. NextResult to check for any more result sets in the DataReader. In the given below example I have taken two table name employee and product.

Example:

SqlConnection con = new SqlConnection ("Data Source=ServerName; Initial Catalog=DatabaseName;Integrated Security=True");
con.Open();
SqlDataReader reader;
SqlCommand cmd = new SqlCommand("select * from employee; select * from product", con);
reader = cmd.ExecuteReader();
do
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Response.Write(reader[i].ToString()+" ");
}
Response.Write("</br>");

}
} while (reader.NextResult()) ;
con.Close();




Q.10 How will you create the SQL Server Connection Objects in Code? Choose the correct option.

A) SqlConnection con = new SqlConnection ("Data Source=ServerName; Initial
Catalog=DatabaseName;Integrated Security=True");

B) SqlConnection con = new SqlConnection();
con.ConnectionString = ("Data Source=ServerName; Initial
catalog=DatabaseName;Integrated Security=True");

C) using (SqlConnection con = new SqlConnection("Data Source=ServerName; Initial
catalog=DatabaseName;Integrated Security=True"))

{
con.Open();
- - - - - -
- - - - - -

}

D) All of the above code are correct.

View Answer / Hide Answer

ANSWER: D

Explanation:

The using statement guarantees that resources are properly cleaned up and in timely manner. The curly braces after using define the scope of the object. When the object goes out of scope it is automatically cleaned up. In the case of our SqlConnection con object, its connection will be closed even though any exception occurs.




Q.11 What are the minimum attribute required to create a connection string using SqlConnection object?

A)
- Data Source
- Initial Catalog
- Integrated security=true

B)
- Server
- Database
- Integrated security=true

C) Option A and B both are correct.

D) None of the above.

View Answer / Hide Answer

ANSWER: C




Q.12 When should you use the OleDbConnection object?

A) When connecting to an Oracle database.
B) When connecting to an Office Access database
C) When connecting to SQL Server 2000
D) None of the above.

View Answer / Hide Answer

ANSWER: B

Explanation:

In this given below example I have used MS Access 2007 and the DataBase File name is Emplyee.accdb and Table name is Emp.

// Namespace used are as follows.
using System;
using System.Data.OleDb;
// Code for retrieve the Emp table data.

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Employee.accdb;Persist Security Info=False");
con.Open();
OleDbDataReader reader;
OleDbCommand cmd = new OleDbCommand("select * from emp", con);
reader = cmd.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
con.Close();




Q.13 What data type is returned when calling the ExecuteScalar method of a command object?

A) System.Int32
B) Object
C) No of effected records.
D) None of the above.

View Answer / Hide Answer

ANSWER: B



Post your comment