You are on page 1of 13

Home work-04

CAP305: WEB PROGRAMMING

Homework Title / No PART-1 & 2 Course Code…1404

Course Instructor: …...Pr.Rishi Chopra Course Tutor (if applicable):

Student’s Roll No.......Rtb012A01 Section No. : .......Tb012.

DOA: 16/10/2010 DOS:21/10/2010

Student’s Signature:
Manoj Sharma.

Q 1). Create a web application with following specifications for a student

Reg. No., Student Name class, Marks in three subjects. This data should

be stored in a table by taking values from user using various HTML

controls. Program should display student details, calculate aggregate

percentage & Grades using following rules:

Marks < 30 Grade F


Marks > 30 & marks < 40 Grade D

Marks > 40 & marks < 60 Grade C

Marks > 60 & marks < 80 Grade B

Marks > 80 Grade A

Program should fetch data from table(s), display all the above information &

store these salary details in the table.

ANS 1.

<html>

<body>

<form method = “post” action =”MARKS.asp>

STUDENT NAME<input type = “text” name=”NAME”>

CLASS<input type = “text” name=”SECTION”>

MARKS IN SUBJECT ONE<input type = “text” name=”M1”>

MARKS IN SUBJECT TWO<input type = “text” name=”M2”>

MARKS IN SUBJECT THREE<input type = “text” name=”M3”>

SUBMIT<input type = “button” name=”submit”>

<%

Set conn1=server.createobject(“ADODB.Connection”)

Conn1.provider=”Microsoft.Jet.OLEDB.4.0”
CONN1.OPEN=”C:\MARKS.ASP”

Server.rst=server.createobject(“ADODB.Recordset”)

Rst.open “Select * from customer”, conn1

%>

<%

Sq=”insert into MARKS values”

Sq=sq & “(‘& request from (“NAME”)&’,”

Sq=sq & “ ‘& request from(“SECTION”)&’,”

Sq=sq & “ ‘& request from(“M1”)&’,”

Sq=sq & “ ‘& request from(“M2”)&’,”

Sq=sq & “ ‘& request from(“M3”)&’,”

Conn.execute sq

%>

<table>

<% do until rst.EOF%>

<tr>

<% for each x in rst field%>

<td><%response. Write(x.value)%></td>

<%next>

</tr>

<%loop>
</table>

</body>

</html>

Q2. Write a program using ASP to read and write binary data into a file which

contains data about an employee.

Ans:
Following is the ASP code of how to read and write binary data into a file:

How to read a binary file:


Function ReadBinaryFile (FileName)
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want to get binary data.


BinaryStream.Type = adTypeBinary

'Open the stream


BinaryStream.Open

'Load the file data from disk to stream object


BinaryStream.LoadFromFile FileName

'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
End Function

Q 3 Write a Web Application using ASP & JavaScript to create a registration

form . Perform necessary validations on various fields of the form.

ANS 3.

<HTML>

<body>

<form method = “post” action =”registration form.asp>

NAME<input type = “text” name=”MY NAME”>

FATHER’S NAME<input type = “text” name=”FNAME”>

AGE<input type = “text” name=”age”>

GENDER<input type = “RADIO” name=”male”>checked

<input type = “GENDER” name=”female”>

ADDRESS<input type = “text” name=”ADDRESS”>

E-MAIL<input type = “text” name=”e-mail”>

SUBMIT<input type = “button” name=”submit”>

<%

Set conn1=server.createobject(“ADODB.Connection”)

Conn1.provider=”Microsoft.Jet.OLEDB.4.0”
CONN1.OPEN=”C:\REGISTRATIONFORM.ASP”

Server.rst=server.createobject(“ADODB.Recordset”)

Rst.open “Select * from customer”, conn1

%>

<%

Sq=”insert into registration values”

Sq=sq & “(‘& request from(“my name”)&’,”

Sq=sq & “ ‘& request from(“father’s name”)&’,”

Sq=sq & “ ‘& request from(“age”)&’,”

Sq=sq & “ ‘& request from(“gender”)&’,”

Sq=sq & “ ‘& request from(“address”)&’,”

Sq=sq & “ ‘& request from(“e-mail”)&’,)”

Conn.execute sq

%>

<table>

<% do until rst.EOF %>

<tr>

<% for each x in rst field%>

<td><%response. Write (x.value)%></td>

<%next>

</tr>
<%loop>

</table>

</body>

</html>

Part-B

Q4. Create a web application with following specifications about an employee

Employee ID, Employee Name Basic Salary, Sex should be stored in a

table by taking values from user using textboxes, Radio buttons etc.

Program should calculate Gross salary using following rules:

D.A. = 54% of Basic Salary

H.R.A. = 5% of Basic Salary

Medical= Rs. 1000

So the Total Salary is Basic Salary + D.A. +H.R.A + Medical

Program should fetch data from table(s), display all the above information &

store these salary details in the table.

ANS 4.

<HTML>

<body>

<form method = “post” action =”EMPLOYEE DETAIL.asp>


EMPLOYEE NAME<input type = “text” name=”name”>

EMPLOYEE ID<input type = “text” name=”ID”>

BASIC SALARY<input type = “text” name=”SALARY”>

GENDER<input type = “RADIO” name=”male”>CHECKED

<input type = “GENDER” name=”female”>

ADDRESS<input type = “text” name=”ADDRESS”>

E-MAIL<input type = “text” name=”e-mail”>

SUBMIT<input type = “button” name=”submit”>

<%

Set conn1=server.createobject(“ADODB.Connection”)

Conn1.provider=”Microsoft.Jet.OLEDB.4.0”

CONN1.OPEN=”C:\EMPLOYEE DETAIL.ASP”

Server.rst=server.createobject(“ADODB.Recordset”)

Rst.open “Select * from customer”, conn1

%>

<%

Sq=”insert into EMPLOYEE DETAIL values”

Sq=sq & “(‘& request from(“NAME”)&’,”

Sq=sq & “ ‘& request from(“ID”)&’,”

Sq=sq & “ ‘& request from(“SALARY”)&’,”

Sq=sq & “ ‘& request from(“GENDER”)&’,”


Sq=sq & “ ‘& request from(“ADDRESS”)&’,”

Sq=sq & “ ‘& request from(“e-mail”)&’,)”

Conn.execute sq

%>

<table>

<% do until rst.EOF %>

<tr>

<% for each x in rst field %>

<td><%response. Write (x.value)%></td>

<%next>

</tr>

<%loop>

</table>

</body>

</html>

Q5. Create a web application in ASP to perform insertion, deletion & updating

records of an educational institute regarding fee details of students.


ANS 5

FOLLOWING IS THE EXAMPLE HOW TO INSERT, UPDATE OR DELETE

RECORDS IN ASP:

FOR INSERTIING AND UPDATING:

<%

if(Request("TextField1") <> "") then Command1__varOne = Request("TextField1")

if(Request("TextField2") <> "") then Command1__varTwo = Request("TextField2")

if(Request("TextField3") <> "") then Command1__varThree = Request("TextField3")

%>

<%

SetCommand1=Server.CreateObject("ADODB.Command")

Command1.ActiveConnection=MM_YourConnection_STRING

Command1.CommandText = "INSERT INTO TableName(Field1, Field2, Field3)

VALUES ('" + Replace(Command1__var1, "'", "''") + "', '" +

Replace(Command1__var2, "'", "''") + "', " + Replace(Command1__var3," ' " ," ''

" ) + " ) "

Command1.CommandType=1

Command1.CommandTimeout=0

Command1.Prepared=true

Command1.Execute()

%>

FOR DELECTING USE THE COMMAND:


DELETE FROM tableName WHERE Field4 = intRecordID

Q6. Create a web application that can be used by a bank to help it in making

new accounts by providing the facility to open an account account.

ANS: 6.

<html>

<body>

<form method = “post” action =”BANK FORM.asp>

NAME<input type = “text” name=”my name”>

Father’s NAME<input type = “text” name=”my name”>

AGE<input type = “text” name=”my name”>

GENDER<input type = “RADIO” name=”male”>checked

<input type = “GENDER” name=”female”>

ADDRESS<input type = “text” name=”ADDRESS”>

E-MAIL<input type = “text” name=”e-mail”>

SUBMIT<input type = “button” name=”submit”>

<%

Set conn1=server.createobject(“ADODB.Connection”)

Conn1.provider=”Microsoft.Jet.OLEDB.4.0”

CONN1.OPEN=”C:\BANKFORM.ASP”
Server.rst=server.createobject(“ADODB.Recordset”)

Rst.open “Select * from customer”, conn1

%>

<%

Sq=”insert into BANK FORM values”

Sq=sq & “(‘& request from(“MY NAME”)&’,”

Sq=sq & “ ‘& request from(“FATHER’S NAME”)&’,”

Sq=sq & “ ‘& request from(“AGE”)&’,”

Sq=sq & “ ‘& request from(“GENDER”)&’,”

Sq=sq & “ ‘& request from(“ADDRESS”)&’,”

Sq=sq & “ ‘& request from(“e-mail”)&’,)”

Conn.execute sq

%>

<table>

<% do until rst.EOF %>

<tr>

<% for each x in rst field%>

<td><%response. Write(x.value)%></td>

<%next>

</tr>

<%loop>
</table>

</body>

</html>

You might also like