1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Imports System.Data.SqlClient
Imports System.Data
Public Class Iseekyou_Users
Public Shared Function UserNameExist(ByVal UserName As String) As Integer
' Chaîne de connexion
Dim _sqlConnectionString As String = ConfigurationManager.ConnectionStrings("bdd_users").ConnectionString
' Objet connection
Dim connection As New SqlConnection(_sqlConnectionString)
' Ouverture
connection.Open()
' Objet Command
Dim command As New SqlCommand("SELECT COUNT(UserName) AS cpt FROM Users WHERE UserName=@UserName", connection)
' Paramètres
command.Parameters.Add(New SqlParameter("@UserName", SqlDbType.VarChar, 30))
command.Parameters("@UserName").Value = UserName
' Object datareader
Dim reader As SqlDataReader = command.ExecuteReader()
Dim cpt As Integer = 0
While reader.Read()
cpt = reader.GetValue(0)
End While
' Fermeture reader
reader.Close()
' Fermeture base
connection.Close()
Return cpt
End Function
End Class |
Partager