SaveEntitiy adding new record

Posts   
 
    
stuarty
User
Posts: 15
Joined: 15-Dec-2008
# Posted on: 27-Jan-2009 17:16:50   

hi I want to get a record and mark Mydown as 1 then update that record, thats what I thought the code was doing below, but its adding a new record with all field blank except Mydown which =1


 DataAccessAdapter adapter = new DataAccessAdapter(); ;
            BarcodesEntity oBarcode = new BarcodesEntity(813824);
            oBarcode.Mydown=1;
            adapter.SaveEntity(oBarcode);



what am I doing wrong now?

thanks once again Stuart

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 27-Jan-2009 21:17:14   

As you are using Adapter you need to fetch the entity from the database yourself. If you modify your code to look like below you should get the result you need.


            DataAccessAdapter adapter = new DataAccessAdapter(); ;
            BarcodesEntity oBarcode = new BarcodesEntity(813824);
           //add the line below
            adapter.FetchEntity(oBarcode);

            oBarcode.Mydown=1;
            adapter.SaveEntity(oBarcode);

Entities only fetch themselves if you are using SelfServicing.

Matt

stuarty
User
Posts: 15
Joined: 15-Dec-2008
# Posted on: 27-Jan-2009 21:47:42   

that worked simple_smile thanks you, thank you , thank you simple_smile

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 27-Jan-2009 22:21:02   

That's what we're here for simple_smile

HTH

Matt