ASP.NET and Databases - MCAST Institute of Information ...

bubblemessengerΑσφάλεια

5 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

89 εμφανίσεις

WORK
SHEET



Institute of Informati
on and Communications Technology

Worksheet 07
-

ASP.NET and Databases

-

Website Management
-

Software

Page |
1

of
3

BTEC

NATIONAL

DIPLOMA

20
10/2011

UNIT

12



W
EB
M
ANAGEMENT

W
ORKSHEET
7



ASP.NET

AND
D
ATABASES

I
NTRODUCTION

Continue working with “
WebsiteDemo
” that you have been building till
Worksheet
5



Navigation in
ASP.NET
.

The following exercises should be implemente
d in this website. Pages
should have the appropriate title.


B
EFORE YOU START
:

C
REATE A NEW DATABASE

Create a new database using SQL Server and name it “
WebsiteDemoDB

. Include the following
fields:



UserId
-

AutoNumber



UserFirst
Name


Text
.



User
Surname


T
ext



User
Address


Text



UserDOB


Short date



User
User
N
ame


Text



User
Password


Text



UserEmail


Text



UserShareInfo


Yes/No



UserAgeGroup


Text


WORK
SHEET



Institute of Informati
on and Communications Technology

Worksheet 07
-

ASP.NET and Databases

-

Website Management
-

Software

Page |
2

of
3

a)

Add some data to the database.

b)

Add the new database to the “
WebsiteDemo
” project.

c)

Save the connection string o
f the new database in the
web.config

file.

d)

Create a “
DatabaseConnection.cs


class in the “
WebsiteDemo


project. All the code that
manipulates the database will be placed here.

E
XERCISE
1:

G
ET A LIST OF ALL REG
ISTERED USERS

a)

In the
DatabaseConnection.cs

cla
ss, add the method “
GetAllUsersBasicInfo

to retrieve
the information of all existing users found in the database. This information should
include the name, surname and username. The method should return a string with this
information.

b)

The result should be

displayed in a label in the “
RegistrationSuccess
” page.

E
XERCISE
2:

I
MPLEMENTING A
S
EARCH FUNCTION

a)

Create a new “
Search
” page.

b)

This page should allow a user to input the
name and surname

of a person. On clicking on
the
submit button
, the address and emai
l of the input user details are shown in a label,
given that the user had decided to allow us to publish his information. If sharing of the
user data is not allowed an appropriate message should be displayed.

c)

The operation of the button should be done in t
he method
GetAddressAndEmail

in the
DatabaseConnection.cs
.
The method should accept 2 strings representing name and
surname. It should return a string with all the necessary information.

d)

Link the “
RegistrationSuccess
” page to the “
Search
” page by mean
s

of
a
LinkButton

in
the

RegistrationSuccess


page
.


WORK
SHEET



Institute of Informati
on and Communications Technology

Worksheet 07
-

ASP.NET and Databases

-

Website Management
-

Software

Page |
3

of
3

E
XERCISE
3:

L
OGIN
F
UNCTIONS USING
D
ATA
S
ETS

a)

Create a new “
Login
” page.

b)

This page should allow a user to input his
username and password
.

On clicking on the
enter button
,
his details are verified against the

database. If the user exists a label in the
same page should display
LOGIN SUCCESSFUL

otherwise an error message should be
displayed.

c)

The operation of the button should be done in the method
LoginFunction

in the
DatabaseConnection.cs
.
The method should ac
cept 2 strings representing
user
name and
password
. It should return a
boolean value.
Datasets should be used in this operation.

d)

Link the “
Home
” page to the “
Login
” page by mean
s

of a
LinkButtons

in both pages.



E
XERCISE
4:

U
SING
D
ATA
B
OUND
C
ONTROLS

a)

Modify
the “
Login
” page function so that on successful login, a
DetailsView

control
displays all the personal information of the
logged person
.

b)

Modify the work done for
exercise 1

such that the information is displayed in a
GridView.

(
Hint: Try using the Data Sou
rce Configuration Wizard
).

c)

Modify the

Gridview

header titles to display appropriate titles.

d)

Add another search function in the “
Search
” page. This should include a drop
-
down list
with the valid age groups. On selecting one of the age groups, a
Gridview

wi
th all the
users in the database whose age range is the chosen one should be displayed. . (
Hint:
Try using the Data Source Configuration Wizard
).

E
XERCISE
5:

I
NSERTING NEW DATA
.

Modify
the “
Register


page such that on clicking the “Submit” button the input

information is
saved to the database.