BCA7 TH CCTpuran Thapa Magar Dot Net Assignment

You might also like

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

Name : Puran Thapa Magar.

Roll no : 17530214
Subject: Dot net programming.
Class: BCA 7th semester

1: a) What is .net? Explain its features.

Answer: .NET ( pronounced as "dot net" ) is a free, cross-platform, open


source developer platform for building different types of applications. It is used
to develop applications for web, windows, phone and moreover it provides
broad range of functionalities and support.
.Net framework consists of large number of class libraries known as
Framework Class Library. The programs written in .Net are executed in
execution environment, which is called as Common Language Runtime.

The features of .Net are as follows:

a) Rich functionality out of box:


.Net Framework provides a rich set of functionality out of box. It
contains hundreds of classes that provides variety of functionality ready
to use in our applications. This means developer doesn’t need to go into
low level details of many operations such as file I/O, network
communication and so on.

b) Easy deployment of web applications:


ASP.Net is technology available on .Net platform for developing
dynamic and data driven web applications. ASP .Net server controls
provides advanced user interface elements like (calendar and grids) that
saves a lot of time in coding.

c) OOPs support:
It provides fully object oriented environment. OOPs makes
development and maintenance easier where we can easily manage the
codes if it grows as per project size grows.

d) Multi language support:


It supports multi languages i.e. if you have skills in C++, it will be more
easier to shift into the .Net environment.
e) Multi device support:
Modern life style is increasingly embracing the wireless devices such as
PDAs, mobiles and handheld PC. .Net is best for all the platform devices.

f) Automatic memory management:


.Net doesn’t needs to worry about memory failure. The garbage collector
takes care of freeing unused objects at appropriate intervals.

g) Strong XML supports:


.Net is the only platform that has built with XML right into core
framework. .Net provides XML web services that are based on standards
like HTTP, XML, SOAP.

1: b) Write a web program to calculate sum of two integer number.

Answer: To calculate sum of any two integer number we have to follow the
steps as follows.

Step 1: Open Visual Studio -> Go to file -> Project


-> Website -> Empty website
Step 2: Add new webform.

Step 3: Drag Label, Textbox and Buttons as required shown in below.

Enter first number:


Enter second number:
Result:

SUM

Now, Double click on Sum Button

protected void Button1.Click()


{
int a = convert.ToInt32(TextBox1.Text);
int b = convert.ToInt32(TextBox2.Text);
int c = a+b;
TextBox3.Text = convert.ToString(c);
}

2: a) What is asp.net? Explain its features.

Answer: ASP (Active Server Page) .Net is a web application framework


developed and marketed by Microsoft to allow programmers to build dynamic
websites. It allows you to use full featured programming such as C# to build
web applications easily.
ASP.Net are used to produce interactive, data driven web applications
over the internet. It consists of large number of controls such as textboxes,
buttons and labels for assembling, configuring and manipulating code to create
HTML pages.
We can write ASP.net application codes in:
- C#
- VisualBasic .Net
- Jscript
- J#

The features of ASP.Net are as follows:

a) Cross platform and container-supports:


With the introduction of .NET Core, we can now create ASP.NET
applications and deploy them to Windows, Linux, and macOS. It
supports in different platform that helps programmers to work and
supports higher.

b) High performance:
ASP.net performs in high speed. It have a higher performance
related to page and server control processing, state management,
data access, application configuration and loading, and efficient
coding practices.
c) Security:
Developing a secure application is most important aspect of
software development process. ASP.NET allow us to add
extensibility points and configuration options that enable us to
customize various security behaviors in the application.

d) State management:
It includes several options that helps you preserve data on both a
per-page basis and an application-wide basis.

e) Debugging and error handling:


Debugging and error handling is the important aspect that helps the
programmers to save time and make less-error code. Debugging
and error handling are well supported within ASP.NET Web Forms
so that our applications compile and run effectively.

f) Multiple environments and development mode:


It allows you to easily differentiate and identify parts of your code
for their behavior in development, staging, production, etc.

2: b) Define a page life cycle. Explain its phases.

Answer: Page life cycle is simply a sequence of events that happen between
the request (hitting page) and response (returning data to user). When an asp.net
page runs, the page goes through lifecycle in which it performs a series of
processing steps.

The different phases of page life cycle are as follows:


a) Initialization
b) Load
c) Control events
d) Rendering
e) Unload
Initialization

Unload Load

Rendering Control events

Figure 1 : Page life cycle.

a) Initialization:
At this stage, the controls on the page are assigned uniqueID by
settting the uniqueID property and the themes are applied. For a
new request, postback data is loaded and controls properties are
restored to the view-state.

b) Load:
During this phase, if page request is postback, control properties
are loaded with information.

c) Control events:
In this stage, event handler is called if page request is postback.
After that, validate method of all validator controls are called.

d) Rendering:
This happens just before all the response information is sent to the
user. All the information on the form is saved, and the result is sent
to the user as a complete webpage.

e) Unload:
At this stage, the requested page has been fully rendered and is
ready to terminate. At this stage all properties are unloaded and
cleanup is performed.
3: a) Define textbox, label, checkbox and radio button with 5 properties.

Answer:
i) TextBox:
TextBox control is most usuable web server controls in asp.net. It
is rectangular box which is used to take user to input.
In simple, Textbox is place where user can input some text in
Asp.ne web form.

webform1.aspx

This is textbox

Properties:

a) ID: Identification name of textbox control.


b) Text: It is used to display text in a control.
c) Textmode: Single/ Multiline/ Password
d) MaxLength: Used to set maximum number of characters that can be input
inTextbox.
e) Backcolor: Used to set background color of textbox control.

ii) Label:
The label control is used to display a text or message to the user on the
form. The label gives indication to the user on what is expected to fill up in
the Textbox.

webform2.aspx

Label
Properties:

a) Font: It is used to set font size of label text.


b) Visible: It is used to set visibility of the control
c) Backcolor: It is used to set background color of the label.
d) Height: It is used to set the height of the label control.
e) Width: It is used to set the width of control.

iii) CheckBox:
CheckBox control is an asp.net web server control. CheckBox control
visually as square on web forms. The Checkbox control allow user to check
square or uncheck square. CheckBox in asp.net allows the user to make binary
choices.

Properties:

a) Checked: used to set check state of the control either true or false.
b) Visible: to set the visibility of control on form.
c) Backcolor: used to set background color of control.
d) Autopostback: True/False.

webform3.aspx

Checkbox

Label

//Double click on Checkbox//

protected void checkbox1…..()


{
if (checkbox1.checked==true)
{
Label1.Text="Right Choice!!!";
}
else
{
Label1.Text="Wrong Choice!!";
}
}

iv) Radio Button:


A radio button or option button is a type of graphical user interface
element that allows the user to choose only one of a predefined set of options.
When a user clicks on a radio button, it becomes checked, and all other radio
buttons with same group become unchecked.

webform4.aspx

user
administrator Radio Button

Properties:

a) Visible: To set visibility of control on webform.


b) Height: It is used to set height of form control.
c) Font: It is used to set font of the form control.
d) Border-width: used to set border of form control.

Properties of RadioButton1
Text=User
AutoPostBack=True

Properties of RadioButton2
Text=Administrator
AutoPostBack=True

//Double click on RadioButton1//


protected void RadioButton1….()
{
Response.Redirect("user.aspx");
}

//Double click on RadioButton2//

protected void RadioButton2….()


{
Response.Redirect("administrator.aspx");
}

3: b) WAP to connect with database (SQL server) using sql data adapter,
display the content of database into data grid view and also facilitate insert
operation.

Answer: To connect with database (SQL) server using sql adapter and
display the content of database into data grid view we have to follow the
different steps. They are as:

Step 1: Open Visual Studio


 Go to file
 Project
 Website
 Empty website

Step 2: Add a new webform

Step 3: Drag Label, Textbox, Buttons from the Toolbox

Step 4: Now go to SQL server


 CREATE DATABASE studentCCT
 INSERT INTO studentCCT (studentID, Name, Address)
VALUES (001, 'John', 'Butwal')

Step 5: Select SQLDatasource


 Click on smart tag
 Configure Datasource
 New connection
 Servername…
 Use window Authentication
 Select created database
 Test connection
 OK
 Next -> Next
 Specify columns from table or viewname
 ..cloumns[] * -> Advanced
 [] Generate Insert, update and delete statement
 OK -> Next -> Test Query -> Finish

Step 6: Now select Gridview -> Click on smart tag ->


Choose data source -> SQL Datasource

Add New column


 Enable paging
 Enable sorting
 Enable editing

Step 7: Now Design your webform as below:

webform1.aspx

Enter student ID:


Enter Name:
Enter Address:

Grid View

SQL DataSource Insert

Step 8: Double click on Insert Button


protected void Button1_click()
{
SqlDataSource1.Insert parameter ["sid"].
Defaultvalue = TextBox1.Text;
SqlDataSource1.Insert parameter ["name"].
Defaultvalue = TextBox2.Text;
SqlDataSource1.Insert parameter ["address"].
Defaultvalue = TextBox3.Text;
` SqlDataSource1.Insert();
Response.write ("<script> alert ("Records has been inserted!!!")
</script>");
}

Step 9: Execute

4: a) Explain given terminologies: sql connection, sql data reader, sql data
adapter.

Answer:
i) Sql connection:
A Sql connection object represents a unique session to a SQL Server data
source. With a client/server database system, it is equivalent to a network
connection to the server. Sql connection is used together with Sql Data Adapter
and Sql command to increase performance when connecting to a Microsoft SQL
Server database.
If the Sql connection goes out of scope, it won't be closed. Therefore, you
must explicitly close the connection by calling Close or Dispose. Close and
Dispose are functionally equivalent. If the connection pooling value Pooling is
set to true or yes, the underlying connection is returned back to the connection
pool. On the other hand, if Pooling is set to false or no, the underlying
connection to the server is actually closed.

Example:
using (SqlConnection connection = new SqlConnection
(connectionString))
{
connection.Open();
}
ii) Sql data reader:
SqlDataReader Object provides a connection oriented data access to the
SQL Server data Sources from C# applications. ExecuteReader() in the
SqlCommand Object sends the SQL statements to the SqlConnection Object
and populate a SqlDataReader Object based on the SQL statement or Stored
Procedures.
When the ExecuteReader method in the SqlCommand Object execute , it
will instantiate a SqlClient.SqlDataReader Object. When we started to read
from a DataReader it should always be open and positioned prior to the first
record. The Read() method in the DataReader is used to read the rows from
DataReader and it always moves forward to a new valid row, if any row exist .

Properties:

a) Connection: It is used to get the SqlConnection associated with the


SqlDataReader.

b) Depth: It is used to get a value that indicates the depth of nesting for the
current row.

c) Field count: It is used to get the number of columns in the current row.

d) HasRows: It is used to get a value that indicates whether the SqlDataReader


contains one or more rows.

e) VisibleFieldCount: It is used to get the number of fields in the


SqlDataReader that are not hidden.

iii) Sql Data Adapter:


SqlDataAdapter Class is a part of the C# ADO.NET Data Provider and it
resides in the System.Data.SqlClient namespace. SqlDataAdapter provides the
communication between the Dataset and the SQL database. We can use
SqlDataAdapter Object in combination with Dataset Object. DataAdapter
provides this combination by mapping Fill method, 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.
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.Fill(ds);
The SqlDataAdapter Object and DataSet objects are combine to perform both
data access and data manipulation operations in the SQL Server Database.
When the user perform the SQL operations like Select , Insert etc. in the data
containing in the Dataset Object , it won't directly affect the Database, until the
user invoke the Update method in the SqlDataAdapter.

4: b) What is master page? Write its importance in web development.


Answer: Master page are the files with master extension. They are used for
designing of web pages. Using master page we create a particular design which
can then be implemented in different .aspx pages.

To create master page


 Go to file -> project -> website
 Empty website

Now, Right click on created website


 Add ->New items ->

Now, click on design section of Master page


webform1.aspx

Image
Content place holder
Image

Then, Again Add webform


 Right click on website -> Add -> New item ->webform

webform1.aspx

select master page


Finally master page is enable in your webform and you can design in your
webform other content id require.

Importance of using master page in web development are as:

- Master page enables consistent and standardized layout of the website.


- We can make layout changes of the site in master page instead of making
changes in pages.
- It is very easy and useful in implement in web development.
- It provides an object model which allows you to customized master page
from individual content pages.
- It allows you to centralize the common functionality of your web pages
so that you can make updates in just one place.

5: a) What is state management? Explain its types.

Answer: State management is a set of techniques using which we can


maintain the data of controls or of the data sources when we send the page to
the server or when we open the browser or when we navigate them from one
page to another.
State management is of 2 types.

State Management

Server side state management Client side state management

Application state View state


Session state Control state
Hidden fields
Cookies
Query string
a) Server side state management: We store the data on the web server
using or in sql server database. The data can be stored on web browser
using "application" and "session object".

i) Application state:
It is a server side state management technique. The data
stored in application state is common for all users of that
particular Asp.net application and can be accessed anywhere
in the application.

ii) Session state:


Session management is a very strong technique to maintain
state. Generally, session is used to store user's information
and or uniquely identify of users. The server maintain state
of users information by using a session ID.
When user make request without a session ID Asp.net
creates a session ID and sends it with every request and
response to same user.

b) Client side state management: The data stored is either in the user's
computer, the address bar of the browser or in hidden field inside the
webpage.
Cookies, Querystring and viewstate are the mechanisms for client
side management.

i) View state:
View state stores any type of data and used for sending and
receiving the information. Sometimes users needs to preserve the
data temporarily after post back, then view state is preferred way of
doing it.

ii) Control state:


The data that is associated with the server control is called
control state. You can persist information about a control
that is not part of view state. If view state is disabled for a
control or the page, the control state is still in work.
iii) Hidden fields:
It is used to store small amount of data on client. It store one
value for the variable and it is preferable way when a
variables value is changed frequently. It stores data without
displaying that control and data to the user's browser.

iv) Cookies:
Cookies are small piece of information that server creates on
the browser. Cookies store a value in the user's browser that
browser sends with every page request to the web server.

5: b) Define validation control. Explain required field validator with


example.

Answer: Validation control is used to perform validations which are useful


in data entry applications. We can perform validation just by setting few
properties and writing almost no code.
Validation control validates the users input data to ensure that useless,
unauthenticated or contradictory data don’t get stored.
There are different types of validation control. They are:
- RequiredFieldValidator
- RangeValidator
- CompareValidator
- RegularExpressionValidator
- CustomValidator

a) RequiredFieldValidator:
The RequiredFieldValidator control ensures that the required
field is not empty. It is generally tied to a text box to force
input into the text box. It is used for checking that data has to
be entered in a particular control, if data is not set/entered it
displays error message.
Properties:

i) ToolTip: It displays the text when mouse is over the control.


ii) ErrorMessage: It is used to set error message that display when validation
fails.

iii) ControlToValidate: It takes ID of control to validate.

iv) Forecolor: It is used to set color of the control text.

v) Visibility: To set visibility of control on the form.

webform1.aspx

Enter your name:

Required field validator

OK

//Double click on Button//


protected void Button1….()
{
Response.Redirect("Default2.aspx");
}
6: a) Write the steps to make report using Microsoft report viewer.

Answer: The steps to make report using Microsoft report viewer in Visual
Studio are given below as:

Step 1: Create a new website and add DataSet to the website.


Right Click on the project, Add new item Dataset, and name it as
Employees.xsd.

Step 2: Adding DataTable to the DataSet.


Our next step would be to add a DataTable to the Type DataSet.

Step 3: Adding Columns or fields to DataTable


In the DataTable we need to specify the column names that we
want to display in the Report.
Step 4: Adding the RDLC Report
Right click on the project and Add New Item, Report
Wizard where we configure our report.
Step 5: Choose the DataSet.
Now we need to choose the DataSet that will act as the DataSource
for the RDLC Report. Thus we need to select the Customers DataSet that we
have created earlier.

Step 6: Choose the Fields to be displayed in the RDLC Report


The next dialog will ask us to choose the layout, we can simply
skip it as of now as this is a simple Report with no calculations involved.
Step 7: Choose the Layout.
The next dialog will ask us to choose the layout, we can simply
skip it as of now as this is a simple Report with no calculations involved.

Step 8: Choose the Style.


Finally we need to choose the style, i.e. color and theme of the
Report.
Once you press Finish button on the above step, the Report is ready and is
displayed in the Visual Studio as shown below.
6: b) What is ADO.NET? Also write its features.

Answer: ADO.NET (ActiveX Data Object .Net) is a software library in


the .Net framework which is used to establish connection between application
and data sources.
Data sources can be such as SQL server and XML. ADO.net consists of
classes that can be used to connect, retrieve, insert and delete data.

Provider objects Common objects

.Net framework Data Provider Data Set

Data Adapter Data table collection


Connection - select
transactions command
- Data Row collection
- insert
Command - Data column collection
command
parameters
- Constraints collection
- update
Data Reader
command
- delete
command Data Relatable Collections

Data-
Base XML

Figure: ADO .NET architecture

The features of ADO .Net are as follows:


a) Bulk copy operation:
Bulk copying of data from data source to another data source is
new feature added in ADO .Net 2.0 version. It provides fastest way
to transfer set of data from one source to another.

b) Batch update:
Batch update can provide a huge improvement in performance by
making just one round tips to server for multiple batches updates.

c) Connection details:
We can get more details about a connection by setting Connection's
statistics enabled property to True.

d) Dataset.RemotingFormat property:
When Dataset.RemotingFormat is set to Binary, the Dataset is
serialized in binary format instead of XML tagged format, which
improves performance of serialization and diserialization
operations significantly.

e) New Data Controls:


In toolbox, we can see new controls DataGridView,
DataConnector, DataNavigator. Using these controls we can
provide navigation support to data in controls.

f) DbProvidersFactories Class:
This class is list of available data providers on machine. We can
use this class and its member to find out best suited data provider
for our database when writing a database independent applications.

g) Customized Data Provider:


By providing the factory classes now ADO .net extends its support
to custom data provider.

7: Write short note on (any two):

a) IIS
Internet Information Server (IIS) is one of the most popular web
servers from Microsoft that is used to host and provide internet-based
services to ASP.net and ASP web applications. A web server is responsible
for providing a response to request that come from users. When a requests
come from clients to server IIS takes that request from users and process it
and send response back to users.

user requests for server received process request


some information request and send back to
user

IIS includes a set of programs for building and administrating web


applications, search engines, and support for writing web-based applications
that access database such as SQL servers.

With IIS we can make our computer to work as web-server and provides
functionality to develop and deploy ASP.net web applications on the server. We
can also set security for particular website for specific users and computer in
order to protect it from unauthorized access.

b) IDE:
An integrated development environment (IDE), also known as
integrated design environment and integrated debugging environment, is a
type of computer software that assists computer programmers to develop
software.
The Visual Studio IDE consists of several sections, or tools, that the
developer uses while programming.

I. Solution Explorer: This is a section that is used to view and


modify the contents of the project. A Visual Studio Windows
Application Project will generally have a Form object with a code
page, references to System components and possibly other modules
with special code that is used by the application.

II. ToolBox: The Toolbox is a palette of developer objects, or


controls, that are placed on forms or web pages, and then code is
added to allow the user to interact with them. An example would
be TextBox, Button and ListBox controls. With these three controls
added to a Windows Form object the developer could write code
that would take text.

III. Properties windows: The properties windows shows all the


control (like TextBox) properties to be changed at design time.
Most of these properties can be also changed with code at run time,
but basically most properties change the way the control is
displayed on your application.

You might also like