Anda di halaman 1dari 9

ASSIGNMENT : 4

COURSE NAME:WEB PROGRAMMING

Submitted to :

Paramjit Singh

Submitted by:

Vivek Jamwal

Sec: B2804

B43
PART A

Q1. Suppose you are given a task of adding a new record to the Customers table in the North wind database.
You first create a form that contains the fields you want to collect data from: Customer id, company name,
contact name, address, city, postal code, country. When the user presses the submit button the form is sent
to a file called "demo_add.asp". The "demo_add.asp" file contains the code that will add a new record to
the Customers table.

Answer: Add a Record to a Table in a Database:-

We want to add a new record to the Customers table in the North wind database. We first create a form that
contains the fields we want to collect data from:

<html>

<body>

<form method="post" action="demo_add.asp">

<table>

<tr>

<td>Customer id:</td>

<td><input type=”text” name="c_id"></td>

</tr><tr>

<td>Company Name:</td>

<td><input type=”text” name="com_name"></td>

</tr><tr>

<td>Contact Name:</td>

<td><input type=”text’ name="cont_name"></td>

</tr><tr>

<td> Enter Address:</td>

<td><input type=”text” name="add"></td>

</tr><tr>

<td> Enter City:</td>


<td><input type=”text” name="city"></td>

</tr><tr>

<td>Zip Code:</td>

<td><input type=”text” name="Zip"></td>

</tr><tr>

<td> Enter Country:</td>

<td><input type=”text” name="country"></td>

</tr>

</table>

<br /><br />

<input type="submit" value="Done">

<input type="reset" value="Clear">

</form>

</body>

</html>

demo_add.asp file:

<html>

<body>

<% set conn=Server.CreateObject("ADODB.Connection")

conn.Provider="Microsoft.Jet.OLEDB.4.0"

conn.Open "c:/webdata/northwind.mdb"

sql="INSERT INTO customers (customerID,companyname,"


sql=sql & "contactname,address,city,postalcode,country)"

sql=sql & " VALUES "

sql=sql & "('" & Request.Form("c_id") & "',"

sql=sql & "'" & Request.Form("com_name") & "',"

sql=sql & "'" & Request.Form("cont_name") & "',"

sql=sql & "'" & Request.Form("add") & "',"

sql=sql & "'" & Request.Form("city") & "',"

sql=sql & "'" & Request.Form("zip") & "',"

sql=sql & "'" & Request.Form("country") & "')"

on error resume next

conn.Execute sql,recaffected

if err<>0 then

Response.Write("No update permissions!")

else

Response.Write("<h3>" & recaffected & " Record added Successfully</h3>")

end if

conn.close

%>

</body>

</html>

Q2. Suppose you r1e working on a table named “Customers” and you want to display the "Companyname"
and "Contactname" fields from the "Customers" table, ordered by "Companyname". Write the code snippet
to sort the records on a specified fieldname using the concept of ADO.
ANS:- <html>
<body>

<%set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"

set r1 = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM
Customers ORDER BY CompanyName"
r1.Open sql, conn
%>

<table border="2" width="80%">


  <tr>
  <%for each x in r1.Fields
    Response.Write("<th>" & x.name & "</th>")
  next%>
  </tr>
  <%do until r1.EOF%>
    <tr>
    <%for each x in r1.Fields%>
      <td><%Response.Write(x.value)%></td>
    <%next
    r1.MoveNext%>
    </tr>
  <%loop
  r1.close
  conn.close%>
</table>

</body>
</html>

Q3. Suppose you want to send information from one page to another using the concept of cookies. But what
if a browser does not support cookies?

Answer:By using a form we can pass the information from one page to another. The form passes the user input
to "a1.asp" when the user clicks on the Submit button:

<form method="post" action="http://127.0.0.1/myweb/a1.asp">


Name: <input type="text" name="name" value="Enter your name" />
Age: <input type="text" name="Age" value="Enter your Age" />
<input type="submit" value="Submit" />
</form>

Retrieve the values in the "a1.asp" file like this:

<%
name=Request.Form("name")
age=Request.Form("Age")
Response.Write("<p>Welcome " & name & ", Your age is: " & Age & " Thank you!</p>")
%>

PART B

Q4. Discuss the three tier architecture in ASP.NET. Does it help in increasing the reusability of code?

Answer: Three-tier application is a program which is organized into three major disjunctive tiers on layers.
These layers are-

3-Tier architecture generally contains UI or Presentation Layer, Business Access Layer (BAL) or Business Logic
Layer and Data Access Layer (DAL).

Presentation Layer (UI)


Presentation layer cotains pages like .aspx or windows form where data is presented to the user or input is
taken from the user.

Business Access Layer (BAL) or Business Logic Layer


BAL contains business logic, validations or calculations related with the data, if needed. I will call it Business
Access Layer in my demo.

Data Access Layer (DAL)


DAL contains methods that helps business layer to connect the data and perform required action, might be
returning data or manipulating data (insert, update, delete etc).

Yes, it definitely helps in increasing the reusability. How these layers increase the reusability of codes
explained below.

Three Tier Code Generator for ASP.NET description


The 3-Tier Code Generator is a tool that will helps developers to code within minutes. It is a simple module to
add, update records into a table. It exploits the object oriented features of .NET. Following are some of the
features of this tool:

It generates all the code required for 3 tier architecture that can be directly used in Visual Studio .NET making
use of Web Template pattern and Error pattern. It Generates SQL procedures and scripts to create, add,
update and show records of the table. Generates code for both C# as well as VB.NET. It can do DataGrid
editing or separate update form. Makes use of cascading style sheets. Uses a standard Microsoft
recommended Microsoft Data Access Application Block for .NET. User controls r1e used for header and footer.

Q5. Discuss the execution process in .NET environment.

Answer:The Execution model:

Unmanaged
Component
VB JS C++ C#

Compiler

Assembly Code

CLR

JIT Compiler
Native Code

Operating System

The managed execution process includes the following steps, which are discussed in detail later in
this topic:

Choosing a Compiler

Compiling to MSIL

. Compiling MSIL to Native Code

Compilation by the JIT Compiler

Code Verification

Q6. Is IIS necessary for publishing the websites under ASP.NET environment? If yes, comment. Also discuss
that if you are working in ASP.NET on Linux platform then what would be used to publish the dynamic web
pages?

Answer: Yes! IIS is necessary for publishing the websites under ASP.NET. Without IIS we have to face difficulty
in publishing the web page.

For Linux platform we use these tools for making the dynamic pages:-

There is an application software named Mono which provides the platform to develop and run .NET client and
server applications on Linux. It can also be deployed on Solaris, Mac OS X, Windows, and Unix. Mono is dual
licensed by Novell, similar to other products such as Qt and the Mozilla Application Suite. Sponsored by Novell,
the Mono open source project has an active and enthusiastic contributing community and is positioned to
become the leading choice for development of Linux applications.
Some Mono Features

Open Source, Free Software,

Based on the ECMA/ISO standards,

Multi-platform,

Runs ASP.NET and Winforms applications,

Can run .NET, Java, Python

* Open Source, Free Software

Now we come to the main essence of this article, i.e running ASP.NET applications on Linux.

Anda mungkin juga menyukai