Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim strSQL As String
Sub BindData()
Dim strConnString As String
strConnString = "Server=localhost\SQLExpress;Database=Myweb;Trusted_Connection=True;"
objConn = New Data.SqlClient.SqlConnection(strConnString)
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM Username WHERE Username = '" & txtUsername.Text & "' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
MsgBox("Username already exist .", MsgBoxStyle.OkOnly, "Warning!!")
Else
End If
strSQL = "INSERT INTO Username (Name,Surname,Username,Password,ConfirmPassword,Email)" & _
" VALUES ('" & txtName.Text & "','" & txtSurname.Text & "','" & txtUsername.Text & "' " & _
" ,'" & txtPassword.Text & "','" & txtConfirmPassword.Text & "','" & txtEmail.Text & "') "
objCmd = New SqlCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
'** Check Password กับ ConfirmPassword ว่าตรงกันไหม **'
Dim sqlPass As String = ""
sqlPass = "SELECT COUNT(*) FROM Username"
sqlPass &= " WHERE (Password = '" & txtPassword.Text & "')"
sqlPass &= " AND (ConfirmPassword = '" & txtConfirmPassword.Text & "')"
objCmd = New SqlCommand(strSQL, objConn)
sqlPass = objCmd.ExecuteScalar()
If sqlPass = 0 Then
lblStatus.Text = "Password is not correct ."
Else
End If
Try
objCmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("บันทึกสำเร็จ", MsgBoxStyle.OkOnly, "Complete")
End Try
objConn.Close()
objConn = Nothing
End Sub
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
BindData()
End Sub