StrataFrame Forum

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

http://forum.strataframe.net/Topic9763.aspx

By Robert Carl Johnson - 6/23/2007

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
By StrataFrame Team - 6/25/2007

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.
By Robert Carl Johnson - 6/25/2007

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
By Trent L. Taylor - 6/25/2007

Correct Smile
By Robert Carl Johnson - 6/25/2007

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
By Trent L. Taylor - 6/25/2007

No problem at all Smile  This is exactly why this forum exists Smile