Posted By

fuzzylogic on 07/23/09


Tagged

username validation


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

smfinlay
haoji


Check if username is in use


 / Published in: VB.NET
 

  1. Function CheckExistingUsername(ByVal username As String) As Boolean
  2.  
  3. Dim UserExists As Boolean = False
  4. Dim strConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("Fullconnection").ConnectionString
  5. Dim MySQL As String = "Select username from tUser where Username=@Username"
  6. Dim MyConn As New SqlConnection(strConn)
  7. Dim objDR As SqlDataReader
  8. Dim Cmd As New SqlCommand(MySQL, MyConn)
  9. Cmd.Parameters.Add(New SqlParameter("@Username", username))
  10.  
  11. Try
  12. MyConn.Open()
  13. objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
  14.  
  15. While objDR.Read()
  16. UserExists = True
  17. End While
  18.  
  19. Catch ex As Exception
  20. LogError("GlobalClass.vb :: CheckExistingUsername", ex.ToString)
  21. Finally
  22. MyConn.Close()
  23. CheckExistingUsername = UserExists
  24. End Try
  25. End Function

Report this snippet  

You need to login to post a comment.