Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Function USerName(ID)" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old July 8th, 2008, 07:58 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default 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
Reply With Quote
Sponsored Links
  #2  
Old July 8th, 2008, 08:02 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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
Reply With Quote
  #3  
Old July 8th, 2008, 08:06 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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?
Reply With Quote
  #4  
Old July 8th, 2008, 08:08 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

I realised that look above
Reply With Quote
  #5  
Old July 8th, 2008, 08:10 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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?
Reply With Quote
  #6  
Old July 8th, 2008, 08:15 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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
Reply With Quote
  #7  
Old July 8th, 2008, 08:17 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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?
Reply With Quote
  #8  
Old July 8th, 2008, 08:18 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Add it outside the Page_Load()

Code:
 
Inherits System.Web.UI.MasterPage
 
Public User As Users = UserManager.GetItem(uID)
 
Sub Page_Load()
.
.
.
Reply With Quote
  #9  
Old July 8th, 2008, 08:19 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

also how will I use it in my Repeater, as i need to convert diff userID's on same
page?
Reply With Quote
  #10  
Old July 8th, 2008, 08:21 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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 With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
export to excel function prompt help Rebelle JavaScript Programming 2 April 14th, 2008 10:40 AM
Concatenation of Column Data function AOG123 Microsoft Access 0 March 25th, 2008 06:53 AM
[ASP.Net/General] VB.Net/C# BBCode Function jmurrayhead Code Samples 0 March 20th, 2008 09:44 AM
[SQL] Concatenation of Column data function.... Lauramc Code Samples 0 March 17th, 2008 12:32 PM


All times are GMT -4. The time now is 07:03 PM.



Content Relevant URLs by vBSEO 3.2.0