Click here to Skip to main content
16,017,881 members

Comments by SajboySajid (Top 1 by date)

SajboySajid 21-Feb-15 11:00am View    
Imports System.Data.SqlClient
Imports System.Data
Imports System.Text.RegularExpressions
Public Class AddUser

Public con As New SqlConnection
Public cmd As New SqlCommand
Public sdr As SqlDataReader
Public sda As SqlDataAdapter
Public ds As New DataSet
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim matchRegex As New Regex("^[a-zA-Z0-9_]{3,16}$")
Dim matches As MatchCollection = matchRegex.Matches(tbUsername.Text)
Try
If tbUsername.Text = "" Then
MsgBox("PLEASE ENTER USERNAME ", MsgBoxStyle.Information, "Login Message")
tbUsername.Focus()

ElseIf tbnewpwd.Text = "" And tbcnfmpwd.Text = "" Then
MsgBox("PLEASE ENTER PASSWORD AND CONFIRM PASSWORD FIELD", MsgBoxStyle.Information, "Login Message")
tbnewpwd.Focus()

ElseIf tbUsername.Text.Length < 3 Then
MsgBox("PLEASE ENTER USERNAME OF MORE THAN THREE CHARACTERS", MsgBoxStyle.Information, "Login Message")
tbUsername.Focus()

'ElseIf tbnewpwd.TextLength < 6 Then
' MsgBox("PLEASE ENTER PASSWORD ATLEAST OF 6 CHARACTER", MsgBoxStyle.Information, "Login Message")
' tbnewpwd.Text = ""
' tbcnfmpwd.Text = ""
' tbnewpwd.Focus()

ElseIf tbcnfmpwd.Text <> tbnewpwd.Text Then
MsgBox(" PASSWORD AND RE-ENTER PASSWORD DOES NOT MATCH", MsgBoxStyle.Information, "LOGIN MESSAGE")
tbnewpwd.Text = ""
tbcnfmpwd.Text = ""
tbnewpwd.Focus()

ElseIf matches.Count = 0 Then
MsgBox("USERNAME CAN NOT CONTAINS SPECIAL CHARACTER ", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Invalid Entry")
tbUsername.Focus()
tbUsername.Text = ""

ElseIf tbnewpwd.Text = tbcnfmpwd.Text Then
If Add_Login() Then
MsgBox("USER ADDED SUCESSFULLY", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "SUCCESSFUL")
tbUsername.Text = ""
tbcnfmpwd.Text = ""
tbnewpwd.Text = ""
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
DBConnection.CloseCon()
End Try
End Sub
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
cbtypeofuser.SelectedIndex = -1
tbUsername.Clear()
tbnewpwd.Clear()
tbcnfmpwd.Clear()
cbtypeofuser.Focus()
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Dim str As String
str = MsgBox("Do you really want to exit", MsgBoxStyle.Critical + MsgBoxStyle.YesNo, "Exit")
If str = vbYes Then
Me.Close()
Else
Me.Refresh()
End If
End Sub
Public Function Add_Login() As Boolean
Dim str As String
str = "INSERT INTO Login(Username,Password,User_Type) VALUES('" & tbUsername.Text & "','" & tbnewpwd.Text & "','" & cbtypeofuser.SelectedItem.ToString & "')"
DBConnection.OpenCon()
cmd = New SqlCommand(str, con)
sda.UpdateCommand = cmd
DBConnection.RetrieveDatabaseQuery(str)
DBConnection.CloseCon()
sda.Dispose()
cmd.Dispose()
Return True

DBConnection.CloseCon()
sda.Dispose()
ds.Dispose()
Return False



End Function

Private Sub AddUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

this is my code when i am trying to add the value an error shows "Object reference not set to instance of an object".
Please help me out