Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

T.Y.B.C.A.

(SEM-VI)
Course: US05CBCA21 (Advanced Web
Development Technology) Question Bank
Unit-IV

MULTIPLE CHOICE QUESTIONS


1 is disconnected, in-memory representation of data.

a) DataReader b) DataSet c) DataAdapter d) DataCommand


Ans:b
2 What is the major component of connected architecture?

a) DataReader b) DataSet c) DataAdapter d) DataCommand


Ans:a
3 method is used to populate DataSet

a) Populate b) Fill c) Open d) Store


Ans:b
4 method returns result set by way of DataReader object.

a) ExecuteDataReader b) ExecuteScaler c) ExecuteNonQuery d)


ExecuteReader
Ans:d
5 For insert, update, and delete SQL commands, method is
used.

a) ExecuteDataReader b) ExecuteScaler c) ExecuteNonQuery d)


ExecuteReader
Ans:c
6 To check whether connection is open or not, method is used.

a) ConnectionStatus b) State c) ConnectionState d) Status


Ans:b
7 To use DataSet namespace needs to be included.

a)System.Data b) System.Data.Oledb c) System.Data.SqlClient d)


System.Data.Sql
Ans:a
8 object provide connection to the database.

a)Command b)Connection c) DataReader


d) DataAdapter
Ans:b
9 In a connection string, represents name of the database.

a) DataSource b) Initial Database c) Initial Catalog d)


Catalog Database
Ans:c
10 If we are not returning any records from the database which method is used?

a)ExecuteReader b) ExecuteScaler c) ExecuteXmlReader d)


ExecuteNonQuery
Ans:d
11 Dataset changes are saved to the database using method.

a)Save b) Update c) Fill


d) None of these
Ans:b
12 DataSets are loaded from the database using method.

a)Save b) Update c) Fill


d) None of these
Ans:c
13 Sorting supports order.

a)Ascending b) Descending c) Both d) None of these


Ans:a
14 SQL SELECT statement are sent to a database using:

a)SqlConnection + b) SqlCommand + c) SqlCommand + d) SqlConnection +


Execute Reader ExecuteNonQuery ExecuteReader ExecuteNonQuery
Ans:c
15 SQL INSERT statement are sent to a database using:

a)SqlConnection + b) SqlCommand + a)SqlConnection + d) SqlConnection +


Execute Reader ExecuteNonQuery Execute Reader ExecuteNonQuery
Ans:b
16 SQL UPDATE statement are sent to a database using:

a)SqlConnection + b) SqlCommand + a)SqlConnection + d) SqlConnection +


Execute Reader ExecuteNonQuery Execute Reader ExecuteNonQuery
Ans:b
17 SQL DELETE statement are sent to a database using:

a)SqlConnection + b) SqlCommand + a)SqlConnection + d) SqlConnection +


Execute Reader ExecuteNonQuery Execute Reader ExecuteNonQuery
Ans:b
18 Retrieving a single value from a returned row involves using:

a)SqlConnection + b) SqlCommand + a)SqlConnection + d) SqlConnection +


Execute Reader ExecuteNonQuery ExecuteScaler ExecuteNonQuery
Ans:c
Short Questions:-

1. Explain difference between DetailsView and GridView.

DetailsView GridView
1 The detailsview control displays only one record Displays the values of a data source in a table
of the data source at a time in the form of a table. where each column represents a field and each
row represents a record.
2 Detailsview control does not support data sorting. Gridview control allows data sorting.

3 Example: Example:

2. Explain the use of server explorer in data access in .net.

The Server Explorer is a tool window that allows you to examine various server resources, including
databases. You can display the Server Explorer with (Ctrl-Alt-S). You can examine databases with the
Server Explorer. One is to expand the tree's Servers node and look in the relevant server's SQL Servers
node. Once you have configured the connection, it will be added to the Data Connections list in the
Server Explorer.

3. Mention the namespace that is used to include .NET Data Provider for SQL server in
.NET code.
System.Data.SqlClient

4. Which namespaces are required to enable the use of databases in ADO .net?

5. What is the use of the Connection object?


Connection object supports a connection to a SQL Server data source. A central property of
connection objects is the ConnectionString property, which holds a string full of attributes/value pairs that
can contain data needed to log on to a data provider and choose specific database.
You can pass the connection string to the connection object’s constructor.
After you’ve created a connection object, you can open it with the open method.

6. What are the usages of the Command object in ADO.NET?

Command objects represents SQL commands or SQL store procedures that you execute in a database. For
example, to retrieve data from a database, you can create a connection object, open the connection with
its open method, and then assign the open connection object to command object with query.
You can pass SQL query and open connection object to constructor of command object, like this:
Dim cmd As New SqlCommand("select * from abc", cn)
(Where cmd is SqlCommand object & cn is SqlConnection object)

7. What is difference between DataSet and DataReader?

8. What is Dataset object?

A dataset is a cache of data retrieved from a database. A dataset object is made up of a collection of
DataTable objects. You can hold multiple tables in a single dataset. SQLDataAdapter is used to fill the data
into a dataset. You can refer the tables by giving them name in your application. Fill method of
SQLDataAdpater is used to fill data into the dataset.

This is how you can use dataset:


Dim ds As New DataSet()
da.Fill(ds, "a")
(Where ds is object of DataSet, da is object of SqlDataAdapter,Fill is used to fill
dataset, “a” is the table name for reference)

9. What is connection string? Explain in brief.

Connection String is a normal String representation which contains Database connection information to
establish the connection between Database and the Application. The Connection String includes parameters
such as the name of the driver, Server name and Database name , as well as security information such as user
name and password.

For Example:

connetionString="Data Source=ServerName;Initial Catalog=Databasename;


User ID=UserName;Password=Password"
10. Explain in brief. (Any one)
− GridView, DataList, DetailsView, FormView, Repeater

1. Gridview Control
This control can display, edit, and delete data in a variety of different data sources in the form of tables.
The gridview control is very powerful. Programmers do not need to write any Code, Drag and drop, set
properties from the property panel, and complete functions such as paging, sorting, and appearance
settings.
2. Datalist Control
This control can display fields of various data sources in a custom format. The format of the displayed
data is defined in the created template, you can create templates for items, alternate items, selected
items, and edit items. The datalist control can also use the title, footer, and delimiter template to
customize the overall appearance, and display multiple data rows in one row. Although the datalist
control has great flexibility, it does not support data paging. Programmers must compile their own
methods to complete the paging function.
3. Detailsview Control
The detailsview control displays only one record of the data source at a time. This control also supports
data editing, insertion, and deletion, and allows you to easily set the paging function. However, the
detailsview control does not support data sorting.
4. Formview Control
Formview control only displays a single record in the data source. Different from the detailsview
control, the detailsview control uses the table layout. Each field in the record is displayed as a row. The
formview control is not used to display the preset layout of records. Programmers need to create
subitem templates and compile various controls used to display fields in records and other HTML labels
for layout. Like the detailsview control, the formview control can easily enable the paging function.
5. Repeater control
Repeater control is a data binding container control, used to generate a list of each sub-item, the Display
Method of these subitems can be completely edited by the programmer. When the control is running on
the page, the control displays the data format defined in the template based on the number of data rows
in the data source. The Repeater control does not provide paging, sorting, editing, and other functions.
These functions must be implemented by programmers themselves.

11. Which properties are used to bind a GridView control?

The DataSource property and the DataMember property are used to bind a DataGridView control. Here,
DataSource refers the object which binds DataGridView,that's generally Dataset/Datatable/or any object.
DataMember refers to Table Name.

12. Explain DataGrid control.

The GridView control is used to display the values of a data source in a table. Each column represents
a field where each row represents a record. The GridView control provides many built-in capabilities
that allow the user to sort, update, delete, select and page through items in the control. The GridView
control can be bound to a data source control, in order to bind a data source control, set the
DataSourceID property of the GridView control to the ID value of the data source control.

13. Explain any one of following namespaces


 System.Data
The System.Data namespace represents the core of ADO.NET. It contains the fundamental
data container classes such as DataSet. Every DataSet contains a collection of DataTable
instances. Each DataTable holds a collection of DataRow objects, each of which contains
the data for a single row. These data classes are independent of any ADO.NET provider.
They simply store disconnected data.

 System.Data.SqlClient
The System.Data.SqlClient namespace contains the provider-specific ADO.NET objects used
to connect to a SQL Server 7 or SQL Server 2000 database, execute a command, and
transfer information to and from a DataSet. The SQL Server .NET provider is optimized
for accessing the SQL Server data source protocol.

 System.Data.OleDB
The System.Data.OleDb namespace contains the provider-specific ADO.NET classes used to
connect to an OLE DB data source, execute a command, and transfer data to and from a
System.Data.DataSet. The OLE DB provider uses COM interop to access the OLE DB
interfaces, so performance will not equal a native provider optimized for a specific data
source.

 System.Data.SqlTypes
The System.Data.SqlTypes namespace contains classes for SQL Server’s native data types,
such as money, tinyint, and varchar. These classes can provide faster access (because
typecasting isn’t required), and eliminate conversion errors.

14. Explain any one of following .NET Data Provider Objects.

Connection
The Connection object is the first component of ADO.NET. The connection object opens a connection to your
data source. All of the configurable aspects of a database connection are represented in the Connection object,
which includes ConnectionString and ConnectionTimeout.
 
Connection object helps in accessing and manipulating a database. Database transactions are also dependent
upon the Connection object.
 
In ADO.NET the type of the Connection is depended on what Database system you are working with. The
following are the commonly used connections in the ADO.NET 

 SqlConnection
 OleDbConnection
 OdbcConnection

Command
 
The Command object is used to perform an action on the data source. Command object can execute stored
procedures and T-SQL commands. You can execute SQL queries to return data in a DataSet or a DataReader
object. Command object performs the standard Select, Insert, Delete, and Update T-SQL operations.
 
DataReader
 
The DataReader is built as a way to retrieve and examine the rows returned in response to your query as quickly
as possible. No DataSet is created; in fact, no more than one row of information from the data source is in
memory at a time. This makes the DataReader quite efficient at returning large amounts of data.
 
The data returned by a DataReader is always read-only.  This class was built to be a lightweight forward-only,
read-only, way to run through data quickly.
  
DataReader object works in a connected model.
 
DataAdapter
 
The DataAdapter takes the results of a database query from a Command object and pushes them into a DataSet
using the DataAdapter.Fill() method. Additionally the DataAdapter.Update() method will negotiate any changes
to a DataSet back to the original data source.
 
DataAdapter object works in a connected model. DataAdapter performs the five following steps: 

1. Create/open the connection


2. Fetch the data as per command specified
3. Generate XML file of data
4. Fill data into DataSet.
5. Close connection

Long Questions

1. Explain the connected architecture of ADO.NET in brief.

Connected Architecture

 As the name suggests, connected architecture refers to the fact that the connection is
established for the full time between the database and application.
 Connected architecture is forward only and read-only. This means the connected
mode will work only in one particular direction. Application issues query then read
back results and process them.
 For connected architecture, we mainly use the object of the DataReader class.
 DataReader is used to retrieve the data from the database and it also ensures that the
connection is maintained for the complete interval of time.
 In connected architecture, the application is directly linked with the Database.

 
 DataReader in Connected architecture

 DataReader class is used to read the data from the database. It works in forward only
and reads the only mode and requires the connection for the complete time. That is
why we use it in connected architecture. The forward only feature makes it an
efficient way to read data. Thus we can say, DataReader is connection-oriented and
requires an active connection while reading the data.

In order to make an object of the DataReader class, we never use the new keyword instead we call
the ExecuteReader() of the command object.

2.Describe the disconnected architecture of ADO.NET's data access model.


 Disconnected architecture refers to the mode of architecture in Ado.net where the
connectivity between the database and application is not maintained for the full time.
Connectivity within this mode is established only to read the data from the database
and finally to update the data within the database.
 This means during the processing of the application, we need data so that data is
fetched from the database and kept in temporary tables. After that whenever data is
required, it is fetched from the temporary tables. And finally, when the operations
were completed, the connection was established to update the data within the
database from the temporary tables.
 In this mode, application issues query then retrieves and store results for processing.
For this purpose, we use objects of SqlDataAdapter and DataSet classes.
 In disconnected architecture, a Dataset is used for retrieving data from the database.
This way there is no need to establish a connection for the full time because DataSet
acts as temporary storage. All the operations can be performed on the data using the
Dataset and finally modified at the database.

DataAdapter in Disconnected architecture

 DataAdapter class acts as an interface between application and database. It provides


the data to the Dataset which helps the user to perform the operations and finally the
modifications are done in the Dataset which is passed to the DataAdapter which
updates the database. DataAdapter takes the decision for the establishment and
termination of the connection.

 DataAdapter is required for connectivity with the database. DataAdapter established


a connection with the database and fetches the data from the database and fill it into
the Dataset. And finally, when the task is completed it takes the data from the
DataSet and updates it into the database by again establishing the connection.

 It can be said that DataAdapter acts as a mediator between the application and
database which allows the interaction in disconnected architecture.
3.Explain major ADO .net objects.

Connection
The Connection object is the first component of ADO.NET. The connection object opens a
connection to your data source. All of the configurable aspects of a database connection are
represented in the Connection object, which includes ConnectionString and
ConnectionTimeout.
 
Connection object helps in accessing and manipulating a database. Database transactions are
also dependent upon the Connection object.
 
In ADO.NET the type of the Connection is depended on what Database system you are
working with. The following are the commonly used connections in the ADO.NET 

 SqlConnection
 OleDbConnection
 OdbcConnection

Command
 
The Command object is used to perform an action on the data source. Command object can
execute stored procedures and T-SQL commands. You can execute SQL queries to return
data in a DataSet or a DataReader object. Command object performs the standard Select,
Insert, Delete, and Update T-SQL operations.
 

DataReader
 
The DataReader is built as a way to retrieve and examine the rows returned in response to
your query as quickly as possible. No DataSet is created; in fact, no more than one row of
information from the data source is in memory at a time. This makes the DataReader quite
efficient at returning large amounts of data.
 
The data returned by a DataReader is always read-only.  This class was built to be a
lightweight forward-only, read-only, way to run through data quickly.
  
DataReader object works in a connected model.
 
DataAdapter
 
The DataAdapter takes the results of a database query from a Command object and pushes
them into a DataSet using the DataAdapter.Fill() method. Additionally the
DataAdapter.Update() method will negotiate any changes to a DataSet back to the original
data source.
 
DataAdapter object works in a connected model. DataAdapter performs the five following
steps: 

 Create/open the connection


 Fetch the data as per command specified
 Generate XML file of data
 Fill data into DataSet.
 Close connection

4.Explain the steps to bind the application with the Database in ADO .net.
Steps:
1. Before working with a database, you have to add .NET Data Provider namespace
Imports System.Data.SqlClient
2. Right click in solution Exploer-> Add New Item-> select service based
database(DataBase1.mdf)
3. Open server Explorer->Create New Table
4. Create a connection object.
5. declare a connection string.

5.Explain the step, how can we retrieve data in DataSet?

The SqlDataAdapter, serves as a bridge between a DataSet and SQL Server for retrieving and
saving data. The SqlDataAdapter provides this bridge by mapping Fill, which changes the
data in the DataSet to match the data in the data source, and Update, which changes the data
in the data source to match the data in the DataSet.
For Example:

SqlConnection con = new SqlConnection("Data Source=localhost;Integrated Security
=SSPI;Initial Catalog=northwind");  
SqlCommand cmd= new SqlCommand("SELECT cid, cnm FROM Cust", con);  
selectCMD.CommandTimeout = 30;  
SqlDataAdapter da = new SqlDataAdapter();  
con.Open();  
DataSet ds = new DataSet();  
da.Fill(ds, "Cust");  
con.Close(); 

6.Explain public methods of SqlCommand objects.

7.What are the four common SQL commands used to retrieve and modify data in a SQL
Database? Also explain each of them.
Four Common SQL Commands : 1. Select 2. Insert 3. Update 4. Delete
Select
Retrives data from one or more tables or views.

Systax : Select * from TableName

Select Columnname1, Columnname2 from TableName


Select * from TableName Where <Condition>
Select * from TableName Order by Columnnane

Example :

Select * from stud Select Sno,Sname from stud;


Select * from stud where city = “Anand” ;
Select * from stud order by total;

Insert
Create a new row and inserts values into specified columns

Syntax: Insert into TableName values(Value1,Value2,…);


Example :

Insert into stud values (1,’ABC’)

Update
Changes the values of individual columns in one or more existing rows in a table.

Syntax : Update TableName set Columnname = value, ….


Update TableName set Columnname = value where <condition>

Example : Update stud set sname = ‘xyz’ where sno = 1;

Delete
Delete one or more rows from a table.

Syntax : Delete from TableName Delete from TableName where <condition>

Example :

Delete from stud Delete from stud where sno = 5;

8.Explain use of “ExecuteScaler” , “ExecuteNonQuery” and “ExecuteReader” method


in detail.

ExecuteNonQuery

ExecuteNonQuery() is one of the most frequently used method in SqlCommand Object and is
used for executing statements that do not return result set. ExecuteNonQuery() performs Data
Definition tasks as well as Data Manipulation tasks also. The Data Definition tasks like
creating Stored Procedures and Views perform by ExecuteNonQuery() . Also Data
Manipulation tasks like Insert , Update and Delete perform by ExecuteNonQuery().

ExecuteReader

ExecuteReader() in SqlCommand Object send the SQL statements to Connection Object and
populate a SqlDataReader Object based on the SQL statement. When the ExecuteReader
method in SqlCommand Object execute, it instantiate a SqlClient.SqlDataReader Object.

The SqlDataReader Object is a stream-based, forward-only, read-only retrieval of query


results from the Data Source, which do not update the data. The SqlDataReader cannot be
created directly from code, they created only by calling the ExecuteReader method of a
Command Object.

ExecuteScaler

ExecuteScalar() in SqlCommand Object is used for get a single value from Database after its
execution. It executes SQL statements or Stored Procedure and returned a scalar value on
first column of first row in the Result Set. If the Result Set contains more than one columns
or rows , it takes only the first column of first row, all other values will ignore. If the Result
Set is empty it will return a Null reference.
It is very useful to use with aggregate functions like Count(*) or Sum() etc. When compare to
ExecuteReader() , ExecuteScalar() uses fewer System resources.

9. Explain in Detail.
− GridView,
− DetailsView
− FormView
− Repeater

Repeater Control

The ASP.NET Repeater is a basic container control that allows you to create custom lists from
any data available to the page. It provides a highly customized interface. It renders a read-only
template; in other words, it supports only the ItemTemplate to define custom binding.

The Repeater control is a Data Bind Control, also known as container controls. The Repeater
control is used to display a repeated list of items that are bound to the control. This control may
be bound to a database table, an XML file, or another list of items.

It has no built-in layout or styles, so you must explicitly declare all layout, formatting and style
tags within the controls templates.

The Repeater control supports the following features:

 List format
 No default output
 More control and complexity
 Item as row
 Paging, Sorting and Grouping requires custom code writing
 Only Web control that allows you to split markup tags across the templates
 No built-in selection capabilities
 No built-in support for edit, insert and delete capabilities

Using the data we stored in table Student of our sample database, the Repeater control will look
like this.
DataList Control

DataList is the next step up from a Repeater. DataList allows you to repeat columns horizontally
or vertically. You can configure the DataList control to enable users to edit or delete a record in
the table. We can use a DataList control where we need a single-column list.

The DataList control works like the Repeater control, used to display the data in a repeating
structure, such as a table. It displays data in a format that you can define using a template and
styles. However, it arranges the data defined in the template within various HTML structures.

This includes options for horizontal or vertical layout and it also allows you to set how the data
should be repeated, as flow or table layout. The DataList control does not automatically use a
data source control to edit data.

The DataList control supports the following features:

 Support for binding data source controls such as SqlDataSource, LinqDataSource and
ObjectDataSource
 Good for columns
 Item as cell
 Updatable
 Control over Alternate item
 Paging function needs handwritten code.

After execution our ListView will look like this.


GridView Control

The GridView control is used to display the values of a data source in a table. Each column
represents a field where each row represents a record. The GridView control provides many
built-in capabilities that allow the user to sort, update, delete, select and page through items in
the control. The GridView control can be bound to a data source control, in order to bind a data
source control, set the DataSourceID property of the GridView control to the ID value of the data
source control.

The GridView control offers improvements such as the ability to define multiple primary key
fields, improved user interface customization using bound fields and templates and a new model
for handling or canceling events.

The GridView control supports the following features:

 Improved data source binding capabilities


 Tabular rendering – displays data as a table
 Item as row
 Built-in sorting capability
 Built-in select, edit and delete capabilities
 Built-in paging capability
 Built-in row selection capability
 Multiple key fields
 Programmatic access to the GridView object model to dynamically set properties, handle
events and so on
 Richer design-time capabilities
 Control over Alternate item, Header, Footer, Colors, font, borders, and so on.
 Slow performance as compared to Repeater and DataList control
Now for the second group. Here is the description of the two controls DetailsView and
FormView.

DetailsView control

The DetailsView control uses a table-based layout where each field of the data record is
displayed as a row in the control. Unlike the GridView control, the DetailsView control displays
one row from a data source.

The DetailsView supports both declarative and programmatic data binding. The DetailsView
control is often used in master-detail scenarios where the selected record in a master control
determines the record to display in the DetailsView control.

It shows the details for the row in a separate space. We can customize the appearance of the
DetailsView control using its style properties. A DetailsView control appears as a form of
recording and is provided by multiple records as well as insert, update and delete record
functions.

The DetailsView control supports the following features:

 Tabular rendering
 Supports column layout, by default two columns at a time
 Optional support for paging and navigation.
 Built-in support for data grouping
 Built-in support for edit, insert and delete capabilities
FormView control

The FormView control renders a single data item at a time from a data source, even if its data
source exposes a multiple records data item from a data source. It allows for a more flexible
layout when displaying a single record.

The FormView control renders all fields of a single record in a single table row. In contrast, the
FormView control does not specify a pre-defined layout for displaying a record. Instead, you
create templates that contain controls to display individual fields from the record.

A FormView is a databound control used to insert, display, edit, update and delete data in
ASP.NET that renders a single record at a time. A FormView control is similar to a DetailView
in ASP.NET but the only difference is that a DetailsView has a built-in tabular rendering
whereas a FormView requires a user-defined template to insert, display, edit, update and delete
data.

The FormView control supports the following features:

 Template driven
 Supports column layout
 Built-in support for paging and grouping
 Built-in support for insert, edit and delete capabilities

You might also like