当我点击注册按钮时,即使我没有在列上输入任何内容,我也会得到测试"registration successful"
。
如果成功插入数据库,我需要显示"registration successful"
如果失败我需要在同一标签上显示"registration fail"
(lblsuccessfail
)
Imports System.Data.SqlClient
Imports System.IO
Partial Class register
Inherits System.Web.UI.Page
Dim cn As New SqlConnection("Data Source=localhost\MSSQL2012;Initial Catalog=UserDetails;Integrated Security=True")
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles btnnew.Click
cn.Open()
Try
Dim Query As String
Query = "INSERT INTO FirstProject (fullname,username,password,address,gender)VALUES('" & txtfullname.Text & "', '" & txtusername.Text & "','" & txtpassword.Text & "','" & txtaddress.Text & "','" & cbogender.Text & "')"
cmd = New SqlCommand(Query, cn)
If cmd.ExecuteNonQuery() Then
lblsuccessfail.Text = lblsuccessfail.Text & " Registertration successful "
End If
Catch ex As Exception
lblsuccessfail.Text = lblsuccessfail.Text & " Registertration unsuccessful "
End Try
cn.Close()
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnback_Click(sender As Object, e As System.EventArgs) Handles btnback.Click
Response.Redirect("login.aspx")
End Sub
End Class
答案 0 :(得分:0)
grep(title$Name, names)