0% found this document useful (0 votes)
1 views

707 ASP Assignment

The document outlines a practical assignment involving the creation of various web pages using ASP.NET. Tasks include demonstrating master pages, navigation controls, user input forms with validation, and CRUD operations on a news table and employee table. Additionally, it includes displaying data in different controls like GridView, DataList, Repeater, and FormView, along with a login page functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

707 ASP Assignment

The document outlines a practical assignment involving the creation of various web pages using ASP.NET. Tasks include demonstrating master pages, navigation controls, user input forms with validation, and CRUD operations on a news table and employee table. Additionally, it includes displaying data in different controls like GridView, DataList, Repeater, and FormView, along with a login page functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

1 505 – Practical Assignment

1.Create a web page to demonstrate use of master page using themes, CSS.

Answer:

Design:

Output:

2. Create a web page to demonstrate the use of navigation controls.


Answer:
Design:

Output:

3. Create the application that accepts name, password, age, email id, and user id. All the information
entry is compulsory. Password should be reconfirmed. Age should be within 21 to 30. Email id should
be valid. User id should have at least a capital letter and digit as well as length should be between 7
and 20 characters.
Answer:

Design:

707-tybca 1
2 505 – Practical Assignment

Output:

4. Consider the following table:


tblnews (newsid, newsdtl, newsdate)

- Create a web page to insert data with proper validation in above table and display data in gridview
control using coding.
Answer:

Design:

Source:

Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Partial Class _Default


Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ToString()


Dim con As New SqlConnection(constring)
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
End Sub

Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click

707-tybca 2
3 505 – Practical Assignment

Try
cmd.CommandText = "insert into tblnews values('" & TextBox1.Text & "','" & Calendar1.SelectedDate & "')"
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
clearcontrols()
con.Close()
End Sub

Sub fillgrid()
Try
cmd.CommandText = "select * from tblnews"
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub

Sub clearcontrols()
TextBox1.Text = ""
End Sub

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
fillgrid()
End Sub
End Class

Output:

- Create a web page to display data in gridview using wizard.


Answer:

Design:

Output:

- Create a Web page to display all the news details provide the update and delete facility on it.
Answer:

Design:

707-tybca 3
4 505 – Practical Assignment

Source:

Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Partial Class Default3


Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ToString()


Dim con As New SqlConnection(constring)
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
End Sub

Sub fillgrid()
Try
cmd.CommandText = "select * from tblnews"
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub

Sub clearcontrols()
TextBox1.Text = ""
End Sub

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
fillgrid()
End Sub

Protected Sub btnupdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupdate.Click


Try
cmd.CommandText = "update tblnews set newsdtl = '" & TextBox1.Text & "',newsdate = '" &
Calendar1.SelectedDate & "' where newsid = " & lblid.Text & ""
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
clearcontrols()
con.Close()
lblid.Text = ""
End Sub

707-tybca 4
5 505 – Practical Assignment

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Try
Dim nid As Integer = GridView1.DataKeys(e.RowIndex).Item(0)
Try
cmd.CommandText = "delete from tblnews where newsid = " & nid & ""
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
clearcontrols()
con.Close()
Catch ex As Exception

End Try
End Sub

Protected Sub GridView1_SelectedIndexChanged (ByVal sender As Object, ByVal e As System.EventArgs)


Handles GridView1.SelectedIndexChanged
Try
Dim nid, ndtl, ndate As Label

nid = CType(GridView1.SelectedRow.FindControl("lblnewsid"), Label)


ndate = CType(GridView1.SelectedRow.FindControl("lblnewsdate"), Label)
ndtl = CType(GridView1.SelectedRow.FindControl("lblnewsdtl"), Label)

lblid.Text = nid.Text
TextBox1.Text = ndtl.Text
CALENDAR1.SelectedDate = ndate.Text
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub

End Class

Output:

- Create a web page that provide date wise searching.


Answer:

Design:

Source:

Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

707-tybca 5
6 505 – Practical Assignment

Partial Class Default4


Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ToString()


Dim con As New SqlConnection(constring)
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
Label1.Text = ex.Message
End Try
'fillgrid()
End Sub

Sub fillgrid()
Try
cmd.CommandText = "select * from tblnews1"
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub
Protected Sub btnsearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsearch.Click
Dim sdate As String = Calendar1.SelectedDate
Try
cmd.CommandText = "select * from tblnews1 where newsdate = '" & sdate & "' "
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
End Try
searchfillgrid()
Label1.Text = sdate
con.Close()
End Sub
Sub searchfillgrid()
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
End Class

Output:

5. Consider the following table:


tblemp(DeptId, DeptName, EmpName, salary).

- Create a web page that provide insert, update and delete functionality with proper validation.
Answer:

Design:

707-tybca 6
7 505 – Practical Assignment

Source:
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Partial Class _Default


Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString


Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable
Dim did As Integer

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
End Sub

Sub fillgrid()
Try
cmd.CommandText = "select * from tblemp order by deptid"
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


Try
If Button1.Text = "Insert" Then
getdeptid()
cmd.CommandText = "insert into tblemp values(" & did & ",'" & DropDownList1.SelectedValue & "','" &
TextBox2.Text & "','" & TextBox3.Text & "')"
con.Open()
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "update tblemp set empname='" & TextBox2.Text & "',salary='" & TextBox3.Text
& "' where deptid=" & Label1.Text & ""
con.Open()
cmd.ExecuteNonQuery()
Button1.Text = "Insert"
End If

Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
clearcontrols()
con.Close()
End Sub

707-tybca 7
8 505 – Practical Assignment

Sub clearcontrols()
TextBox2.Text = ""
TextBox3.Text = ""
End Sub

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
Try
GridView1.PageIndex = e.NewPageIndex
fillgrid()
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub

Sub getdeptid()
Try
did = DropDownList1.SelectedIndex + 101
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Try
Dim d_did As Integer = GridView1.DataKeys(e.RowIndex).Item(0)
Dim d_empname As String = GridView1.DataKeys(e.RowIndex).Item(1)

cmd.CommandText = "delete from tblemp where deptid = " & d_did & " and empname = '" & d_empname
& "' "
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
End Try
fillgrid()
con.Close()
End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged
Try
Dim ldname, lename, lsalary As Label

ldname = CType(GridView1.SelectedRow.FindControl("lbldeptname"), Label)


lename = CType(GridView1.SelectedRow.FindControl("lblempname"), Label)
lsalary = CType(GridView1.SelectedRow.FindControl("lblsalary"), Label)

DropDownList1.SelectedValue = ldname.Text
TextBox2.Text = lename.Text
TextBox3.Text = lsalary.Text
Label1.Text = DropDownList1.SelectedIndex + 101

Button1.Text = "Update"

Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub
End Class

Output:

- Create a web page to display all records in Data list controls.

707-tybca 8
9 505 – Practical Assignment

Answer:

Design:

Source:
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Partial Class Default2


Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString


Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
End Try
fillgrid()
End Sub

Sub fillgrid()
Try
cmd.CommandText = "select * from tblemp order by deptid"
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
DataList1.DataSource = dt
DataList1.DataBind()
Catch ex As Exception
End Try
End Sub
End Class

Output:

- Create a web page to display all records in Repeater controls.


Answer:

Design:

Source:
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Partial Class Default3


Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

707-tybca 9
10 505 – Practical Assignment

Dim con As New SqlConnection


Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
End Try
fillgrid()
End Sub

Sub fillgrid()

Try
cmd.CommandText = "select * from tblemp order by deptid"
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
Repeater1.DataSource = dt
Repeater1.DataBind()
Catch ex As Exception
End Try
End Sub
End Class

Output:

- Create a web page to display all records in form view controls.


Answer:

Design:

Source:
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Partial Class Default4


Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString


Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
End Try
fillgrid()
End Sub
Sub fillgrid()
Try
cmd.CommandText = "select * from tblemp order by deptid"
da = New SqlDataAdapter(cmd)
dt = New DataTable

707-tybca 10
11 505 – Practical Assignment

da.Fill(dt)
FormView1.DataSource = dt
FormView1.DataBind()
Catch ex As Exception
End Try
End Sub
End Class

Output:

6. Create a Login page. After successfully login, page is redirect to home page, which displays
Username and logout option.
Answer:

Design of Login Page:

Source of Login Page:


Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString


Dim con As New SqlConnection(constring)
Dim cmd As New SqlCommand
Dim dr As SqlDataReader

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


Try
cmd.CommandText = "select * from tbllogin where username='" & TextBox1.Text & "' and password='" &
TextBox2.Text & "' "
con.Open()
dr = cmd.ExecuteReader()

If dr.HasRows = True Then


Session("username") = TextBox1.Text
Response.Redirect("~/Home.aspx")
Else
Label1.Text = "UserName and Password does not match"
End If
Catch ex As Exception
Label1.Text = ex.Message
End Try
con.Close()
End Sub

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load


Try
con.ConnectionString = constring
cmd.Connection = con
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub
End Class

Output of Login Page:

707-tybca 11
12 505 – Practical Assignment

Design of Home Page:

Source of Home Page:


Partial Class Home
Inherits System.Web.UI.Page

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load


Label1.Text = Session("username")
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


Response.Redirect("~/Default.aspx")
End Sub
End Class
Output of Home Page:

7. Create website using .net technology for online shopping of gifts. Give facility to register as admin
who can add various categories of gifts. The admin can also add, update or delete any gift articles on
the site. Users can register and view various gift articles and place orders using COD mode only.

Answer:

Design For Admin:

Source:

Imports System.Data.SqlClient

Imports System.Data

Imports System.IO

Partial Class adminpanel

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString()

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Dim filepath, filepath1 As String

Dim flag As Boolean = False

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

lbladmin.Text = Session("admin")

707-tybca 12
13 505 – Practical Assignment

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

img_main.Visible = False

End Sub

Sub fillgrid()

Try

cmd.CommandText = "select * from tblgiftmaster where admin='" & lbladmin.Text & "'"

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

Protected Sub Button_Main_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Button_Main.Click

Try

If Button_Main.Text = "Insert" Then

If FileUpload1.HasFile = True Then

filepath = "~/images/" + FileUpload1.FileName

FileUpload1.SaveAs(Server.MapPath("~/images/") + FileUpload1.FileName)

End If

cmd.CommandText = "insert into tblgiftmaster values('" & txtgname.Text & "','" & txtgprice.Text & "','" &
lbladmin.Text & "','" & filepath & "')"

Else

If FileUpload1.HasFile = True Then

filepath1 = "~/images/" + FileUpload1.FileName

FileUpload1.SaveAs(Server.MapPath("~/images/”) +FileUpload1.FileName)

flag = True

Dim dimg As String = Server.MapPath(img_main.ImageUrl)

If File.Exists(dimg) Then

File.Delete(dimg)

End If

img_main.Visible = False

End If

707-tybca 13
14 505 – Practical Assignment

If flag Then

cmd.CommandText = "update tblgiftmaster set gname='" & txtgname.Text & "',gprice='" &
txtgprice.Text & "',filepath='" & filepath1 & "' where gid = " & lblerror.Text & ""

Else

cmd.CommandText = "update tblgiftmaster set gname='" & txtgname.Text & "',gprice='" &
txtgprice.Text & "' where gid = " & lblerror.Text & ""

End If

End If

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

con.Close()

txtgname.Text = ""

txtgprice.Text = ""

End Sub

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging

Try

GridView1.PageIndex = e.NewPageIndex

fillgrid()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting

Try

Dim gid As Integer = GridView1.DataKeys(e.RowIndex).Item(0)

Dim vimage As String = GridView1.DataKeys(e.RowIndex).Item(1)

cmd.CommandText = "delete from tblgiftmaster where gid =" & gid & " "

con.Open()

cmd.ExecuteNonQuery()

Dim fileexists As String = Server.MapPath(vimage)

If File.Exists(fileexists) Then

File.Delete(fileexists)

End If

Catch ex As Exception

lblerror.Text = ex.Message

End Try

707-tybca 14
15 505 – Practical Assignment

fillgrid()

con.Close()

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged

Try

img_main.Visible = True

Dim g_id, g_name, g_price, g_admin As Label

Dim gimage As Image

g_id = CType(GridView1.SelectedRow.FindControl("lblid"), Label)

g_name = CType(GridView1.SelectedRow.FindControl("lblname"), Label)

g_price= CType(GridView1.SelectedRow.FindControl("lblprice"), Label)

g_admin=CType(GridView1.SelectedRow.FindControl("lbl_admin"), Label)

gimage = CType(GridView1.SelectedRow.FindControl("Image1"), Image)

lblerror.Text = g_id.Text

txtgname.Text = g_name.Text

txtgprice.Text = g_price.Text

img_main.ImageUrl = gimage.ImageUrl

Button_Main.Text = "Update"

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

End Class

OutPut:

Design For User:

Source of User:

Imports System.Data.SqlClient

Imports System.Data

Imports System.IO

Partial Class Userhome

Inherits System.Web.UI.Page

707-tybca 15
16 505 – Practical Assignment

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString()

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Label1.Text = Session("User")

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

End Try

filldatalist()

End Sub

Sub filldatalist()

Try

cmd.CommandText = "select * from tblgiftmaster"

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

Catch ex As Exception

End Try

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged

Try

Dim g_id, g_name, g_admin, g_price As Label

Dim image As Image

g_id = CType(GridView1.SelectedRow.FindControl("lblid"), Label)

g_name = CType(GridView1.SelectedRow.FindControl("lblname"), Label)

g_admin=CType(GridView1.SelectedRow.FindControl("lbl_admin"), Label)

g_price =CType(GridView1.SelectedRow.FindControl("lblprice"), Label)

image = CType(GridView1.SelectedRow.FindControl("Image1"), Image)

lblggid.Text = g_id.Text

Response.Redirect("~/Product.aspx?gid=" & g_id.Text & "&gname=" & g_name.Text & "&gprice=" &
g_price.Text & "&admin=" & g_admin.Text & "&image=" & image.ImageUrl)

Catch ex As Exception

End Try

End Sub

707-tybca 16
17 505 – Practical Assignment

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging

Try

GridView1.PageIndex = e.NewPageIndex

filldatalist()

Catch ex As Exception

lblggid.Text = ex.Message

End Try

End Sub

End Class

Output of User penal:

Product Design:

Source of Product:

Partial Class Product

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Label1.Text = Request.QueryString("gid")

lblname.Text = Request.QueryString("gname")

lblprice.Text = Request.QueryString("gprice")

lblseller.Text = Request.QueryString("admin")

Image1.ImageUrl = Request.QueryString("image")

End Sub

Protected Sub btnpaymnet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles


btnpaymnet.Click

MultiView1.ActiveViewIndex = 0

Label2.Text = lblprice.Text

End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

MultiView1.ActiveViewIndex = -1

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

707-tybca 17
18 505 – Practical Assignment

If RadioButton1.Checked Then

Label3.Text = ""

Response.Redirect("~/Userhome.aspx")

Else

Label3.Text = "Please checked radio button"

End If

End Sub

End Class

Output of Product Design:

8. Create .NET based module that can be used for online missing person registration and processing
site where user can register and enter information about missing person. Create appropriate tables
and provide appropriate validations.

Answer:

Design:

Source:

Imports System.Data.SqlClient

Imports System.Data

Partial Class _Default

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim gender, filepath As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

End Try

End Sub

Protected Sub Button1_Click (ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

707-tybca 18
19 505 – Practical Assignment

If FileUpload1.HasFile = True Then

filepath = "~/images/" + FileUpload1.FileName

FileUpload1.SaveAs(Server.MapPath("~/images/") + FileUpload1.FileName)

End If

If RadioButton1.Checked Then

gender = "Male"

End If

If RadioButton2.Checked Then

gender = "Female"

End If

Try

cmd.CommandText = "insert into tblmissingperson values('" & TextBox1.Text & "','" & TextBox2.Text & "'," &
TextBox3.Text & ",'" & gender & "','" & Calendar1.SelectedDate & "','" & Calendar2.SelectedDate & "','" &
TextBox4.Text & "','" & TextBox5.Text & "','" & filepath & "')"

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

End Try

con.Close()

TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

TextBox5.Text = ""

RadioButton1.Checked = False

RadioButton2.Checked = False

End Sub

End Class

9. Design module using ASP.NET "shoponline" for online shopping which provide online

shopping items like jeans shirts, shirt etc. It includes view of items along with their price.

Add selected items into cart and display shipping details. Provide proper validation.

Answer:

Design of Home Page:

Source:

Imports System.Data

707-tybca 19
20 505 – Practical Assignment

Partial Class home

Inherits System.Web.UI.Page

Dim db As New dbhelper()

Protected Sub AddToCart_Click(ByVal sender As Object, ByVal e As EventArgs)

Dim button As System.Web.UI.WebControls.Button = CType(sender, System.Web.UI.WebControls.Button)

Dim productId As Integer = Convert.ToInt32(button.CommandArgument)

Dim data As DataTable = db.getData("select * from tblcart where uid = 1 and pid = " & productId & "")

If data.Rows.Count > 0 Then

MasterPage.ShowAlert(Me, "product already exist in the cart")

Return

End If

db.exeQuery("insert into tblcart(uid,pid) values(1," & productId & ")")

MasterPage.ShowAlert(Me, "product added to cart")

End Sub

End Class

Dbhelper class:

Imports Microsoft.VisualBasic

Imports System.Data.SqlClient

Imports System.Data

Public Class dbhelper

Dim constr As String = ConfigurationManager.ConnectionStrings("cns").ToString()

Dim con As New SqlConnection(constr)

Dim cmd As New SqlCommand

Sub New()

cmd.Connection = con

End Sub

Sub exeQuery(ByVal query As String)

cmd.CommandText = query

con.Open()

cmd.ExecuteNonQuery()

con.Close()

End Sub

Function getData(ByVal query As String) As DataTable

cmd.CommandText = query

Dim dt As New DataTable

Dim da As New SqlDataAdapter(cmd)

con.Open()

da.Fill(dt)

con.Close()

Return dt

End Function

707-tybca 20
21 505 – Practical Assignment

End Class

Design for Cart:

Source:

Imports System.Data

Partial Class show_cart

Inherits System.Web.UI.Page

Dim db As New dbhelper()

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim data As DataTable = db.getData("select * from tbluser where uid = 1")

lblUserName.Text = data.Rows(0).Item(1)

lblAddress.Text = data.Rows(0).Item(2)

lblCity.Text = data.Rows(0).Item(4)

lblState.Text = data.Rows(0).Item(3)

SqlDataSource2.SelectCommand = "select c.cart_id as cart_id,p.* from tblproducts p ,tblcart c where p.id =


c.pid and c.uid = 1"

End Sub

End Class

10. Design module using ASP.NET "online book shop" for online book shopping. User can view the
different category of books and place an order for book. Admin can manage the book stock. Provide
proper validation.

Answer:

Design for User:

Source for User:

Imports System.Data.SqlClient

Imports System.Data

Imports System.IO

Partial Class user

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

707-tybca 21
22 505 – Practical Assignment

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

End Try

fillgrid()

End Sub

Sub fillgrid()

cmd.CommandText = "select * from tblbook"

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged

Dim bid, bname, bprice, stock As Label

bid = CType(GridView1.SelectedRow.FindControl("lblid"), Label)

bname = CType(GridView1.SelectedRow.FindControl("lblname"), Label)

bprice = CType(GridView1.SelectedRow.FindControl("lblprice"), Label)

stock = CType(GridView1.SelectedRow.FindControl("lblstock"), Label)

Response.Redirect("~/Product.aspx?bid=" & bid.Text & "&bname=" & bname.Text & "&bprice=" & bprice.Text
& "&stock=" & stock.Text)

End Sub

End Class

Design for Product:

Source for Product:

Partial Class Product

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Label1.Text = Request.QueryString("bid")

Label2.Text = Request.QueryString("bname")

707-tybca 22
23 505 – Practical Assignment

Label3.Text = Request.QueryString("bprice")

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Response.Redirect("~/user.aspx")

End Sub

End Class

Design for Admin:

Source for Admin:

Imports System.Data.SqlClient

Imports System.Data

Imports System.IO

Partial Class Admin_Panel

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

End Sub

Sub fillgrid()

cmd.CommandText = "select * from tblbook"

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

End Sub

707-tybca 23
24 505 – Practical Assignment

Protected Sub Button_main_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Button_main.Click

Try

If Button_main.Text = "Insert" Then

cmd.CommandText = "insert into tblbook values('" & TextBox1.Text & "','" & TextBox2.Text & "','" &
TextBox3.Text & "')"

Else

cmd.CommandText = "update tblbook set bname='" & TextBox1.Text & "',stock='" & TextBox2.Text &
"',bprice='" & TextBox3.Text & "' where bid = " & lblid.Text & ""

Button_main.Text = "Insert"

lblid.Text = ""

End If

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

con.Close()

clear()

End Sub

Sub clear()

TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

End Sub

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting

Try

Dim id As Integer = GridView1.DataKeys(e.RowIndex).Item(0)

cmd.CommandText = "delete from tblbook where bid=" & id & ""

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

con.Close()

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged

Try

Dim bid, bname, bprice, stock As Label

707-tybca 24
25 505 – Practical Assignment

bid = CType(GridView1.SelectedRow.FindControl("lblid"), Label)

bname = CType(GridView1.SelectedRow.FindControl("lblname"), Label) bprice =


CType(GridView1.SelectedRow.FindControl("lblprice"), Label) stock =
CType(GridView1.SelectedRow.FindControl("lblstock"), Label)

lblid.Text = bid.Text

TextBox1.Text = bname.Text

TextBox2.Text = stock.Text

TextBox3.Text = bprice.Text

Button_main.Text = "Update"

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

End Class

11. Create interactive pages using .NET which accept Information pertaining to Airline booking. It
store information in the database using entry form and display information for given Booking-id. Use
following table for this purpose: Bookig master (booking_id, booking date, Name, address, contact_no,
Source_Place, Destination_Place). Provide appropriate validations.

Answer:

Design:

Source:

Imports System.Data.SqlClient

Imports System.Data

Imports System.IO

Partial Class _Default

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

Label1.Text = ex.Message

707-tybca 25
26 505 – Practical Assignment

End Try

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

cmd.CommandText = "insert into tblbooking values('" & Calendar2.SelectedDate & "','" & TextBox1.Text &
"','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

Label1.Text = ex.Message

End Try

con.Close()

TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

Try

cmd.CommandText = "select * from tblbooking where bid=" & TextBox5.Text & ""

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

Catch ex As Exception

End Try

End Sub

End Class

12. Create a website for Domino’s Pizza and give facility for ordering items. Maintain session for
logged in users.

Answer:

Design:

Source:

Imports System.Data.SqlClient

Imports System.Data

707-tybca 26
27 505 – Practical Assignment

Imports System.IO

Partial Class Default2

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

End Try

fillgrid()

End Sub

Sub fillgrid()

cmd.CommandText = "select * from tblpizza"

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged

Try

Dim price As Label

Dim photo As Image

photo = CType(GridView1.SelectedRow.FindControl("Image1"), Image)

price = CType(GridView1.SelectedRow.FindControl("Label1"), Label)

Response.Redirect("~/Default.aspx?photo=" & photo.ImageUrl & "&price=" & price.Text)

Catch ex As Exception

End Try

End Sub

End Class

Design for Order:

707-tybca 27
28 505 – Practical Assignment

Source for Design:

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Image1.ImageUrl = Request.QueryString("photo")

Label1.Text = Request.QueryString("price")

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Response.Redirect("~/Default2.aspx")

End Sub

End Class

13. Develop a .NET application for "E-Shopping system" will provide features like:

- Admin/user login page

- Admin can insert, update, and delete products information in database.

- Create appropriate database tables for this and provide appropriate validations.

Answer:

Design For Admin:

Source:

Imports System.Data.SqlClient

Imports System.Data

Imports System.IO

Partial Class adminpanel

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString()

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Dim filepath, filepath1 As String

707-tybca 28
29 505 – Practical Assignment

Dim flag As Boolean = False

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

lbladmin.Text = Session("admin")

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

img_main.Visible = False

End Sub

Sub fillgrid()

Try

cmd.CommandText = "select * from tblgiftmaster where admin='" & lbladmin.Text & "'"

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

Protected Sub Button_Main_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Button_Main.Click

Try

If Button_Main.Text = "Insert" Then

If FileUpload1.HasFile = True Then

filepath = "~/images/" + FileUpload1.FileName

FileUpload1.SaveAs(Server.MapPath("~/images/") + FileUpload1.FileName)

End If

cmd.CommandText = "insert into tblgiftmaster values('" & txtgname.Text & "','" & txtgprice.Text & "','" &
lbladmin.Text & "','" & filepath & "')"

Else

If FileUpload1.HasFile = True Then

filepath1 = "~/images/" + FileUpload1.FileName

FileUpload1.SaveAs(Server.MapPath("~/images/")+FileUpload1.FileName)

flag = True

Dim dimg As String = Server.MapPath(img_main.ImageUrl)

If File.Exists(dimg) Then

File.Delete(dimg)

707-tybca 29
30 505 – Practical Assignment

End If

img_main.Visible = False

End If

If flag Then

cmd.CommandText = "update tblgiftmaster set gname='" & txtgname.Text & "',gprice='" &
txtgprice.Text & "',filepath='" & filepath1 & "' where gid = " & lblerror.Text & ""

Else

cmd.CommandText = "update tblgiftmaster set gname='" & txtgname.Text & "',gprice='" &
txtgprice.Text & "' where gid = " & lblerror.Text & ""

End If

End If

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

con.Close()

txtgname.Text = ""

txtgprice.Text = ""

End Sub

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging

Try

GridView1.PageIndex = e.NewPageIndex

fillgrid()

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting

Try

Dim gid As Integer = GridView1.DataKeys(e.RowIndex).Item(0)

Dim vimage As String = GridView1.DataKeys(e.RowIndex).Item(1)

cmd.CommandText = "delete from tblgiftmaster where gid=" & gid & " "

con.Open()

cmd.ExecuteNonQuery()

Dim fileexists As String = Server.MapPath(vimage)

If File.Exists(fileexists) Then

File.Delete(fileexists)

End If

707-tybca 30
31 505 – Practical Assignment

Catch ex As Exception

lblerror.Text = ex.Message

End Try

fillgrid()

con.Close()

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged

Try

img_main.Visible = True

Dim g_id, g_name, g_price, g_admin As Label

Dim gimage As Image

g_id = CType(GridView1.SelectedRow.FindControl("lblid"), Label)

g_name = CType(GridView1.SelectedRow.FindControl("lblname"), Label)

g_price = CType(GridView1.SelectedRow.FindControl("lblprice"), Label)

g_admin = CType(GridView1.SelectedRow.FindControl("lbl_admin"), Label)

gimage = CType(GridView1.SelectedRow.FindControl("Image1"), Image)

lblerror.Text = g_id.Text

txtgname.Text = g_name.Text

txtgprice.Text = g_price.Text

img_main.ImageUrl = gimage.ImageUrl

Button_Main.Text = "Update"

Catch ex As Exception

lblerror.Text = ex.Message

End Try

End Sub

End Class

14. Develop "Online Complaint System" by providing following functionality.

Technician:

- Login

- View and Update status (Pending solved) of the complaint

Registered user:

- Give complaints according to services (Hardware / Software/ Internet)

Answer:

Design of Technician Panel:

Source of Technician Panel:

707-tybca 31
32 505 – Practical Assignment

Imports System.Data.SqlClient

Imports System.Data

Partial Class technician

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim da As SqlDataAdapter

Dim dt As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

End Try

fillgrid()

End Sub

Sub fillgrid()

cmd.CommandText = "select * from tblcomplaint"

da = New SqlDataAdapter(cmd)

dt = New DataTable

da.Fill(dt)

GridView1.DataSource = dt

GridView1.DataBind()

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles


GridView1.SelectedIndexChanged

Try

Dim cid, com, complaint, state As Label

cid = CType(GridView1.SelectedRow.FindControl("lblid"), Label)

com = CType(GridView1.SelectedRow.FindControl("lblcom"), Label)

complaint = CType(GridView1.SelectedRow.FindControl("lblcomplaint"), Label)

state = CType(GridView1.SelectedRow.FindControl("lblstate"), Label)

Label1.Text = cid.Text

If com.Text = RadioButton1.Text Then

RadioButton1.Checked = True

End If

If com.Text = RadioButton2.Text Then

RadioButton2.Checked = True

End If

If com.Text = RadioButton3.Text Then

707-tybca 32
33 505 – Practical Assignment

RadioButton3.Checked = True

End If

TextBox1.Text = complaint.Text

If state.Text = "Pending" Then

DropDownList1.SelectedIndex = 0

End If

If state.Text = "Solve" Then

DropDownList1.SelectedIndex = 1

End If

Catch ex As Exception

End Try

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

cmd.CommandText = "update tblcomplaint set state='" & DropDownList1.SelectedValue & "' where cid=" &
Label1.Text & ""

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

End Try

fillgrid()

con.Close()

DropDownList1.SelectedIndex = 0

TextBox1.Text = ""

RadioButton1.Checked = False

RadioButton2.Checked = False

RadioButton3.Checked = False

End Sub

End Class

User Panel for Complaint:

Source:

Imports System.Data.SqlClient

Imports System.Data

Partial Class complaint

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

707-tybca 33
34 505 – Practical Assignment

Dim com As String

Dim s As String = "Pending"

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

If RadioButton1.Checked Then

com = RadioButton1.Text

End If

If RadioButton2.Checked Then

com = RadioButton2.Text

End If

If RadioButton3.Checked Then

com = RadioButton3.Text

End If

Try

cmd.CommandText = "insert into tblcomplaint values('" & com & "','" & TextBox1.Text & "','" & s & "')"

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

End Try

con.Close()

TextBox1.Text = ""

RadioButton1.Checked = False

RadioButton2.Checked = False

RadioButton3.Checked = False

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

End Try

End Sub

End Class

15. Develop the "Missing Person Information Management System" for police department by

providing following functionality.

Police: - View information of missing person - Login

Relative: - Register and provide missing person information

Guest User: - If any, provide additional information

Answer:

Design:

707-tybca 34
35 505 – Practical Assignment

Source:

Imports System.Data.SqlClient

Imports System.Data

Partial Class _Default

Inherits System.Web.UI.Page

Dim constring As String = ConfigurationManager.ConnectionStrings("cns").ToString

Dim con As New SqlConnection(constring)

Dim cmd As New SqlCommand

Dim gender, filepath As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

con.ConnectionString = constring

cmd.Connection = con

Catch ex As Exception

End Try

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

If FileUpload1.HasFile = True Then

filepath = "~/images/" + FileUpload1.FileName

FileUpload1.SaveAs(Server.MapPath("~/images/") + FileUpload1.FileName)

End If

If RadioButton1.Check

gender = "Male"

End If

If RadioButton2.Checked Then

gender = "Female"

End If

Try

cmd.CommandText = "insert into tblmissingperson values('" & TextBox1.Text & "','" & TextBox2.Text & "'," &
TextBox3.Text & ",'" & gender & "','" & Calendar1.SelectedDate & "','" & Calendar2.SelectedDate & "','" &
TextBox4.Text & "','" & TextBox5.Text & "','" & filepath & "')"

con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception

End Try

con.Close()

TextBox1.Text = ""

707-tybca 35
36 505 – Practical Assignment

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

TextBox5.Text = ""

RadioButton1.Checked = False

RadioButton2.Checked = False

End Sub

End Class

16. Develop module using .NET to keep track of visitors in museum which stores visitor’s details like
name, time of visit, date of visit, contact no, etc. Also give facility to search and display visitor’s data
based on the date visited.

Answer:

Design:

Source:

Dbhelper class:

Imports Microsoft.VisualBasic

Imports System.Data.SqlClient

Imports System.Data

Public Class dbhelper

Dim constr As String = ConfigurationManager.ConnectionStrings("cns").ToString()

Dim con As New SqlConnection(constr)

Dim cmd As New SqlCommand

Sub New()

cmd.Connection = con

End Sub

Sub exeQuery(ByVal query As String)

cmd.CommandText = query

con.Open()

cmd.ExecuteNonQuery()

con.Close()

End Sub

Function getData(ByVal query As String) As DataTable

cmd.CommandText = query

Dim dt As New DataTable

Dim da As New SqlDataAdapter(cmd)

con.Open()

707-tybca 36
37 505 – Practical Assignment

da.Fill(dt)

con.Close()

Return dt

End Function

End Class

Partial Class addVisitor

Inherits System.Web.UI.Page

Dim db As New dbhelper()

Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click

Dim insertQuery As String = "INSERT INTO VisitorRecords (Name, DateOfVisit, ContactNo, Email) " & _

"VALUES ('" & txtname.Text & "', '" & dt.SelectedDate.ToString("yyyy-MM-dd") & "', '" & txtcon.Text & "', '" &
txtemail.Text & "')"

db.exeQuery(insertQuery)

lblmsg.Text = "Record inserted"

End Sub

End Class

Design for Search:

Source:

Partial Class showData

Inherits System.Web.UI.Page

Dim db As New dbhelper()

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

GridView1.DataSource = db.getData("select * from VisitorRecords")

GridView1.DataBind()

End Sub

Protected Sub btnFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter.Click

GridView1.DataSource = db.getData("select * from VisitorRecords WHERE DateOfVisit = '" +


dt.SelectedDate.ToString("yyyy-MM-dd") + "'")

GridView1.DataBind()

End Sub

End Class

707-tybca 37

You might also like