On Thu, Sep 2, 2010 at 8:25 AM, Kent Belan <[email protected]> wrote:
> Hello,
>
> Just wondering how others handle this situation, maybe there is a better
> way.
>
> I have a parent / child setup, where I pull a cursor of the child records
> and then allow add/edit/delete on the child cursor.
>
> How do you update the DBF with the child records ?
>
> This is easy when there are no child records found, just add all records
> from cursor.
>
> The hard part is when an existing child record is deleted from the cursor.
>
> How do you make sure the same record gets deleted from the live DBF and also
> update or add the changed or new records from the cursor ?
>
-----------------------

>From your child collection you iterate through it knowing if you need
to delete the row or not.  If NOT then you are in Update or Add mode.
Will a new child have a key yet?  That could be your flag.  If the key
is auto generated before data contact (make a guid a head of time)
just query for it, if found update else insert.

This is C# code but it follows what to do:
 public static String setOrg(Orgs oOrg, Guid oAppUserID, Boolean AddNew)
        {
            using (ELogs2Entities EL = new ELogs2Entities())
            {
                if (AddNew)    // flag set for Insert
                {
                    Organization ORG = new Organization();  // get
structure  then load up data
                    ORG.CreDate = DateTime.Now;
                    ORG.CreUser = oAppUserID;
                    ORG.OrganizationAddress = oOrg.organizationAddress;
                    ORG.OrganizationId = oOrg.organizationId;
                    ORG.OrganizationName = oOrg.organizationName;
                    ORG.OrganizationPhone = oOrg.organizationPhone;
                    ORG.Deleted = oOrg.deleted;
                    ORG.QueryTypeID = oOrg.queryTypeId;
                    ORG.QueryParam = oOrg.queryParam;
                    ORG.DocumentReturnType = oOrg.documentReturnType;
                    EL.AddToOrganization(ORG);
                 // Insert here
                }
                else                  // Find the row you want
                {
                    var ORG = (from o in EL.Organization
                               where o.OrganizationId == oOrg.organizationId
                               select o).First();
                    ORG.OrganizationAddress = oOrg.organizationAddress;
                    //ORG.OrganizationId = oOrg.organizationId;
                    ORG.DocumentReturnType = oOrg.documentReturnType;
                    ORG.OrganizationName = oOrg.organizationName;
                    ORG.OrganizationPhone = oOrg.organizationPhone;
                    ORG.QueryParam = oOrg.queryParam;
                    ORG.Deleted = oOrg.deleted;
// Deleted flag in table
                    ORG.ModDate = DateTime.Now;
                    ORG.ModUser = oAppUserID;
                    ORG.QueryTypeID = oOrg.queryTypeId;

                }

                int saveit = EL.SaveChanges();           // Commit the
data to the back end.

                return saveit >0 ? "cool" : "Organization failed to save";
            }
        }

-- 
Stephen Russell

Sr. Production Systems Programmer
CIMSgts

901.246-0159 cell

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to