本文整理匯總了VB.NET中System.Web.Security.RoleProvider.GetRolesForUser方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET RoleProvider.GetRolesForUser方法的具體用法?VB.NET RoleProvider.GetRolesForUser怎麽用?VB.NET RoleProvider.GetRolesForUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了RoleProvider.GetRolesForUser方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: GetRolesForUser
Public Overrides Function GetRolesForUser(ByVal username As String) As String()
If username Is Nothing OrElse username = "" Then _
Throw New ProviderException("User name cannot be empty or null.")
Dim tmpRoleNames As String = ""
Dim conn As OdbcConnection = New OdbcConnection(connectionString)
Dim cmd As OdbcCommand = New OdbcCommand("SELECT Rolename FROM UsersInRoles " & _
" WHERE Username = ? AND ApplicationName = ?", conn)
cmd.Parameters.Add("@Username", OdbcType.VarChar, 255).Value = username
cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName
Dim reader As OdbcDataReader = Nothing
Try
conn.Open()
reader = cmd.ExecuteReader()
Do While reader.Read()
tmpRoleNames &= reader.GetString(0) & ","
Loop
Catch e As OdbcException
' Handle exception.
Finally
If Not reader Is Nothing Then reader.Close()
conn.Close()
End Try
If tmpRoleNames.Length > 0 Then
' Remove trailing comma.
tmpRoleNames = tmpRoleNames.Substring(0, tmpRoleNames.Length - 1)
Return tmpRoleNames.Split(CChar(","))
End If
Return New String() {}
End Function