Professional Documents
Culture Documents
U4 QB Solution
U4 QB Solution
(SEM-VI)
Course: US05CBCA21 (Advanced Web
Development Technology) Question Bank
Unit-IV
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:
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?
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)
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.
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:
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.
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.
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.
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.
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:
Long Questions
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.
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:
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.
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();
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.
Example :
Insert
Create a new row and inserts values into specified columns
Update
Changes the values of individual columns in one or more existing rows in a table.
Delete
Delete one or more rows from a table.
Example :
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.
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.
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.
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.
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.
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.
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.
Template driven
Supports column layout
Built-in support for paging and grouping
Built-in support for insert, edit and delete capabilities