16,017,881 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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