I am trying to use GetByPrimaryKey() in my Function but having problems


Author
Message
Robert Carl Johnson
Robert Carl Johnson
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)
Group: Forum Members
Posts: 48, Visits: 130
Hi all. I have a login form that has a combo box that lists users. When the user selects himself his ID ( a primary key value in the table) is loaded in lnValue and sent to my function GetEmployeeByID. The idea is to get the execute the query and return the one record based on the ID value using the GetByPrimaryKey Method. For some reason no matter what value is sent thru ID the return is always from the first record with a ID value of 1. I have used the debugger to check values of ID to the function and it is 2 that is being sent but when I get back to my form the password in the dataset is from record 1. Clear as mud? In other words I'm asking for record 2 and am getting record 1. So,is my code correct or have I not understood your example of how to use the GetByPrimaryKey? BWT, ID is the primary key for this table.



Regards,



Robert



---CODE FROM MY FORM------

Dim lnValue as Integer

'-- Get the ID from the selected name in the combo box

lnValue = CType(txtFullName.SelectedValue, Integer)



'-- Send the ID to the Function that will get the Password from the DB of the selected user

Me.EmployeeBO1.GetEmpoyeeByID(lnValue)



---CODE FROM MY EMPOYEEBO1-------

Public Function GetEmpoyeeByID(ByVal ID As Integer)



Return Me.GetByPrimaryKey(ID)



End Function

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
It looks like your problem is that you're using the GetByPrimaryKey() instead of FillByPrimaryKey() within the GetByEmployeeID() method.  If the business object is already filled, and you call GetByPrimaryKey(), it won't change anything within the business object... it will just return a new DataTable containing the information you requested rather than filling the business object with the data that you want.  So, when you check Me.EmployeeBO1, it's data isn't going to change when you call GetByEmployeeID().  What you want to do is change the GetByEmployeeID() to a Sub and change the "Return Me.GetByPrimaryKey(ID)" to "Me.FillByPrimaryKey(ID)" (there's nothing to return since it takes the requested data and puts it inside the business object.
Robert Carl Johnson
Robert Carl Johnson
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)
Group: Forum Members
Posts: 48, Visits: 130
Ben, thanks for the reply. So to recap, I am going to use your suggested method because I already have a dataset and I want to view another record from it, correct? I would only use GetByPrimaryKey(Pk) when I need to get another dataset.



Regards,



Robert
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Correct Smile
Robert Carl Johnson
Robert Carl Johnson
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)
Group: Forum Members
Posts: 48, Visits: 130
Rock n' Roll. I'm getting there.. lol.



Thanks guys. I appreciate the patience with a newbie to .Net I spent a lot of years in another language so this stuff is quite new to me but I'm getting my head around it.



Robert
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
No problem at all Smile  This is exactly why this forum exists Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search