University Questions With Answer: B.SC - It/Cs Department of Rizvi College of Arts, Science and Commerce
University Questions With Answer: B.SC - It/Cs Department of Rizvi College of Arts, Science and Commerce
DataProvider DataSet
DataReader DataStore
Q.No 2: What is DataReader in ADO.NET? Explain with example? OR Give details about
DataReader with example?(Nov 18,May19)
1. DataReader provides an easy way for the programmer to read data from a database as if it
were coming from a stream.
2. The DataReader is the solution for forward streaming data through ADO.NET.
3. DataReader is also called a firehose cursor or forward read-only cursor because it moves
forward through the data.
4. The DataReader not only allows us to move forward through each record of database, but
it also enables us to parse the data from each column.
5. The DataReader class represents a data reader in ADO.NET.
6. DataReader is like a forward only recordset.
7. It fetches one row at a time so very less network cost compare to DataSet(Fethces all the
rows at a time).
8. DataReader is readonly so we can't do any update or transaction on them.
9. DataReader will be the best choice where we need to show the data to the user which
requires no transaction.
10. As DataReader is forward only so we can't fetch data randomly.
11. NET Data Providers optimizes the DataReader to handle huge amount of data.
12. Performance is good.
13. DataReader is a connection oriented architecture.
namespace CommandTypeEnumeration
{
classProgram
{
staticvoid Main(string[] args)
{
while (reader.Read())
{
Console.Write(reader["CustomerID"].ToString() + ", ");
Console.Write(reader["ContactName"].ToString() + ", ");
Console.Write(reader["ContactTitle"].ToString() + ", ");
Console.WriteLine(reader["Address"].ToString() + ", ");
}
//Release resources
reader.Close();
conn.Close();
}
}
}
Configuring various data operations on operations on the underlying data depends upon the
various properties (property groups) of the datasource contrtol.
Properties of SqlDataSource control used for programmin g interface of the control.
publicpartialclasssudentdetails : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
Prof. Haider_Zaidi Page 5
B.Sc - IT/CS DEPARTMENT OF RIZVI COLLEGE OF
ARTS, SCIENCE AND COMMERCE
{
}
protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = newSqlConnection();
conn.ConnectionString = ("Data Source=hp;Initial Catalog=studentinfo;Integrated
Security=True");
try
{
conn.Open();
SqlCommand cmd = newSqlCommand(query, conn);
SqlDataAdapter da = newSqlDataAdapter();
da.SelectCommand = cmd;
1. ASP.NET application services are built-in Web services that provide access to features
such as forms authentication, roles, and profile properties.
2. These services are part of a service-oriented architecture (SOA), in which an application
consists of one or more services provided on the server, and one or more clients.
3. For more information about SOA, see Understanding ServiceOriented Architecture on
the MSDN Web site.
4. An important feature of ASP.NET application services is that they are available to a
variety of client applications, not just ASP.NET Web applications.
Background
Every ASP.NET web form control inherits the DataBind method from its parent Control class,
which gives it an inherent capability to bind data to at least one of its properties. This is known
as simple data binding or inline data binding.
Simple data binding involves attaching any collection (item collection) which implements the
IEnumerable interface, or the DataSet and DataTable classes to the DataSource property of the
control.
On the other hand, some controls can bind records, lists, or columns of data into their structure
through a DataSource control. These controls derive from the BaseDataBoundControl class. This
is called declarative data binding.
Simple data binding involves the read-only selection lists. These controls can bind to an array list
or fields from a database. Selection lists takes two values from the database or the data source;
one value is displayed by the list and the other is considered as the value corresponding to the
display.
Let us take up a small example to understand the concept. Create a web site with a bulleted list
and a SqlDataSource control on it. Configure the data source control to retrieve two values from
your database (we use the same DotNetReferences table as in the previous chapter).
When the application is executed, check that the entire title column is bound to the bulleted list
and displayed.
We have already used declarative data binding in the previous tutorial using GridView control.
The other composite data bound controls capable of displaying and manipulating data in a
tabular manner are the DetailsView, FormView, and RecordList control.
In the next tutorial, we will look into the technology for handling database, i.e, ADO.NET.
Q.No :10 Explain the ways of formatting GridView Data for display(May 19)
The GridView is an extremely flexible grid control for showing data in a basic grid consisting of
rows and columns. It has selection, paging and editing feature, and it is extensible through
templates. The great advantage of Gridview over Datagrid is its support for code free scenarios.
In GridView you can do many things without writing any code like paging and selection.
FormattingFields:
To format the grid view you have to ensure that dates, currency and other number values are in
good format. Grid View has property "DataFormatString" to apply formatting. You can change
colors, fonts, borders and alignment of grid. Each BoundField column provides a
DataFormatString property that you can use to configure the numbers and dates using a format
string.
Format strings are generally made up of a placeholder and format indicator, which are wrapped
inside curly brackets, like this:
{0:C}
Here 0 shows the value that will be formatted and the letter indicates a predetermined format
style. In this case C means currency format which formats a number as a dollar.
Here we are going to discuss about few format strings, if you want to know in details then you
can search on msdn.
Header Style: Set the header row style that contains column titles if you do ShowHeader
property true.
RowStyle: Set the style of every data row.
AlternatingRowStyle: Set the style of every alternate row in gridview.
SelectedRowStyle: Set the style of currently selected row.
EditRowStyle: Set the style of row that is in edit mode. This formatting acts in addition to the
RowStyle formatting.
EmptyDataRowStyle: Set the style that is used fro the single row in the special case where the
bound data object contains no rows.
FooterStyle: Set the style of the footer row at the bottom of the GridView, if you choose
ShowFooter property true.
PagerStyle: Set the style of the row with the page links if you enable AllowPaging property true.
Example:
Q.No 11: Write a short note on selecting grid view row (May 19)
A GridView allows us to select only a single row at a time. The sample makes use of the
database. We will be pulling data from the UserDetail table.
Creating Table in SQL Server Database
Now create a table named UserDetail with the columns UserID and UserName. The table looks
as below.
First of all drag the GridView control from the Data controls menu. It will add the GridView
control's HTML source code as given above.
In the above GridView Properties set 'AutoGenerateSelectButton=True'. See the following image
of a GridView after setting 'AutoGenerateSelectButton=True'. Select the GridView and press F4
for the property window.
See the Design view of your GridView. You will find a Hyperlink with a text as 'Select'.
1. using System.Data.SqlClient;
2. using System.Data;
Now double-click on the page and write the following code for binding the data with the
GridView.
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. using System.Data.SqlClient;
8. using System.Data;
9. namespace WebApplication120
10. {
11. public partial class WebForm1 : System.Web.UI.Page
12. {
13. protected void Page_Load(object sender, EventArgs e)
14. {
15. show();
16. }
17. private void show()
Selecting Row
Selecting the row event is fired when you make a click on the select link. If you need any
particular item in that row you can easily select it using the cells property. In the Gridview,
double-Click on the SelectedIndexChanged Event and write the following code:
Now run the application and select a row; that will show the selected row data in the TextBoxes.