Write a program to create the Registration. Field Names are: First name, Middle name, Last Name, address, contact no, email id, gender, city, state, country and photo. Set the proper validation. A. Insert the data in the database on click of submit button. B. Display the registration form information in the Grid view. 2. Write
AppCode file
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Public Class DAL
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim dt As DataTable
Public Sub New()
cn = New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)
End Sub
Public Sub exeNonQuery(ByVal s As String)
Try
cmd = New SqlCommand(s, cn)
cn.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex)
Finally
cn.Close()
End Try
End Sub
Public Function getSrno(ByVal tblName As String) As String
Dim x As String
Dim s = "select case count(*) when 0 then 1 else max(srno)+1 end from " & tblName
cmd = New SqlCommand(s, cn)
cn.Open()
x = cmd.ExecuteScalar()
cn.Close()
Return x
End Function
Public Function getDataset(ByVal s As String) As DataSet
ds = New DataSet
cmd = New SqlCommand(s, cn)
Try
cn.Open()
da = New SqlDataAdapter(cmd)
da.Fill(ds, "tbl")
Catch ex As Exception
Finally
cn.Close()
End Try
Return ds
End Function
End Class
Defult.aspx
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim obj As DAL
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
fillGrid()
End If
End Sub
Public Sub fillGrid()
obj = New DAL
GridView1.DataSource = obj.getDataset("select * from registration")
GridView1.DataBind()
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
HiddenField1.Value = GridView1.DataKeys(GridView1.SelectedIndex).Value
Dim ds As New DataSet
Dim obj As New DAL
ds = obj.getDataset("select * from registration where srno=" & HiddenField1.Value)
txtfname.Text = ds.Tables(0).Rows(0)("fname").ToString
txtmname.Text = ds.Tables(0).Rows(0)("mname").ToString
txtlname.Text = ds.Tables(0).Rows(0)("lname").ToString
txtaddress.Text = ds.Tables(0).Rows(0)("address").ToString
txtcontact.Text = ds.Tables(0).Rows(0)("contactno").ToString
txtemail.Text = ds.Tables(0).Rows(0)("emailid").ToString
If ds.Tables(0).Rows(0)("gender").ToString.Trim = "M" Then
RadioButton2.Checked = True
Else
RadioButton1.Checked = True
End If
txtcity.Text = ds.Tables(0).Rows(0)("city").ToString
txtstate.Text = ds.Tables(0).Rows(0)("state").ToString
txtcountry.Text = ds.Tables(0).Rows(0)("country").ToString
End Sub
Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
obj = New DAL
Dim gen As String = "Male"
If RadioButton2.Checked = True Then
gen = "Female"
End If
Dim s As String = "insert into registration(srno,fname,mname,lname,address,contactno,emailid,gender,city,state,country) values" & _
"(" & obj.getSrno("registration").ToString & ", '" & txtfname.Text & "', '" & txtmname.Text & "','" & txtlname.Text & "','" & txtaddress.Text & "', " & txtcontact.Text & ",'" & txtemail.Text & "','" & gen & "','" & txtcity.Text & "', '" & txtstate.Text & "','" & txtcountry.Text & "')"
obj.exeNonQuery(s)
fillGrid()
End Sub
End Class
Registration connectivity in ASP
Reviewed by Unknown
on
3:15 pm
Rating:
No comments: