+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 26

Thread: Function USerName(ID)

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Function USerName(ID)

    hi guys, once again i'm stuck

    I did try for a while on my own, i know it's sad
    anywho moving on, as the name suggests I want to create a function to
    return a users name based on their user ID.

    here's the page where i tried to write the function:
    Code:
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.ComponentModel
    Imports Keith.ProjectManager.BO
    
    Namespace Keith.ProjectManager.Bll
    
        Public Class Common
            Public Shared Sub CheckLogIn()
                If Len(HttpContext.Current.Session("UserName")) < 1 Or HttpContext.Current.Session("UserName") = "Guest" Then
                    HttpContext.Current.Session("UserName") = ""
                    HttpContext.Current.Session("UserID") = ""
                    HttpContext.Current.Response.Redirect("default.aspx")
    
                    Dim LogOutMsg As String
                    LogOutMsg = "Your session has expired"
                End If
            End Sub
    
            Public Shared Function GetUSerName(ByVal uID As Integer) As String
                Dim UserList As New UserList
                UserList = UserManager.GetItem(uID)
    
                Dim myUser As New Users
                Return myUser.Name
            End Function
        End Class
    
    End Namespace
    
    Usermanager Bll: (only relevant code)
    Code:
    <DataObjectMethod(DataObjectMethodType.Select, False)> _
            Public Shared Function GetItem(ByVal id As Integer) As Users
                Return UserDB.GetItem(id)
            End Function
    
    UserDB DAL:
    Code:
    Public Shared Function GetItem(ByVal id As Integer) As Users
                Dim myUser As Users = Nothing
                ' Using
                Dim myConnection As MySqlConnection = New MySqlConnection(myConfig.myConnection)
                Try
                    Dim myCommand = New MySqlCommand(QueryUserDB.Item(id), myConnection)
                    myConnection.Open()
                    'Using
                    Dim myReader As MySqlDataReader = myCommand.ExecuteReader
                    Try
                        If myReader.Read Then
                            myUser = FillDataRecord(myReader)
                        End If
                        myReader.Close()
                    Finally
                        CType(myReader, IDisposable).Dispose()
                    End Try
                    myConnection.Close()
                Finally
                    CType(myConnection, IDisposable).Dispose()
                End Try
                Return myUser
            End Function
    
    Private Shared Function FillDataRecord(ByVal myDataRecord As IDataRecord) As Users
                Dim myUser As Users = New Users
                myUser.Idkey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("idkey"))
                myUser.Name = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("name"))
                myUser.Email = myDataRecord.GetString(myDataRecord.GetOrdinal("email"))
                myUser.Password = myDataRecord.GetString(myDataRecord.GetOrdinal("psswrd"))
                Return myUser
            End Function
    
    the error, this is before i have even tried to use it anywhere:
    Code:
     Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
    
    Compiler Error Message: BC30311: Value of type 'Keith.ProjectManager.BO.Users' cannot be converted to 'Keith.ProjectManager.BO.UserList'.
    
    Source Error:
    
    Line 20:         Public Shared Function GetUSerName(ByVal uID As Integer) As String
    Line 21:             Dim UserList As New UserList
    Line 22:             UserList = UserManager.GetItem(uID)
    Line 23: 
    Line 24:             Dim myUser As New Users
    
    
    Source File: C:\Inetpub\wwwroot\keithdesign\App_Code\global\BLL\Common.vb    Line: 22
    
    Shem

  2. #2
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    fixed that error

    Code:
    Public Shared Function GetUSerName(ByVal uID As Integer) As String
                Dim Users As New Users
                Users = UserManager.GetItem(uID)
    
                Dim myUser As New Users
                Return myUser.Name
            End Function
    
    Shem

  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    UserList = UserManager.GetItem(uID)

    UserManager.GetItem returns a Users Object not a List.

    Are you trying to get a list of User Names or an individual one?

  4. #4
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    I realised that look above

  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Shem View Post
    fixed that error

    Code:
    Public Shared Function GetUSerName(ByVal uID As Integer) As String
                Dim Users As New Users
                Users = UserManager.GetItem(uID)
     
                Dim myUser As New Users
                Return myUser.Name
            End Function
    
    Shem
    OK...Posted as I was replying. Why are you creating another instance of the Users object?

    Why not just have Return Users.Name?

    And then, why is this not just in your page code? If you wanted to use it a lot, just create the instance in your Master Page

    .master
    Code:
    Public User As Users = UserManager.GetItem(uID)
    
    .aspx.vb
    Code:
    label1.text = Master.User.Name
    
    Or am I missing something here?

  6. #6
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    no your not missing anything, I most likely am
    I just did it that way as that's how I am used to doing things?

    so in my masterpage.master.vb i just add:
    Code:
    Public User As Users = UserManager.GetItem(uID)
    
    in my Page_Laod()?

    Shem

  7. #7
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Quote Originally Posted by richyrich View Post
    OK...Posted as I was replying. Why are you creating another instance of the Users object?
    I went by your example that you did for me when we populated Projects?

  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Add it outside the Page_Load()

    Code:
     
    Inherits System.Web.UI.MasterPage
     
    Public User As Users = UserManager.GetItem(uID)
     
    Sub Page_Load()
    .
    .
    .
    

  9. #9
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    also how will I use it in my Repeater, as i need to convert diff userID's on same
    page?

  10. #10
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Shem View Post
    I went by your example that you did for me when we populated Projects?
    Code:
            Public Shared Function GetUSerName(ByVal uID As Integer) As String
                Dim UserList As New UserList
                UserList = UserManager.GetItem(uID)
    
                Dim myUser As New Users
                Return myUser.Name
            End Function
    
    I don't remember doing anything like that....

+ Reply to Thread
Page 1 of 3 1 2 3 LastLast

Similar Threads

  1. export to excel function prompt help
    By Rebelle in forum JavaScript Programming
    Replies: 2
    Last Post: April 14th, 2008, 11:40 AM
  2. Concatenation of Column Data function
    By AOG123 in forum Access Database Samples
    Replies: 0
    Last Post: March 25th, 2008, 07:53 AM
  3. VB.Net/C# BBCode Function
    By jmurrayhead in forum .NET Code Samples
    Replies: 0
    Last Post: March 20th, 2008, 10:44 AM
  4. Concatenation of Column data function....
    By Lauramc in forum SQL Code Samples
    Replies: 0
    Last Post: March 17th, 2008, 01:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO