• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1271
  • Last Modified:

How do you update a field in a record using LINQ

I have a record in a table.  I want to update the date field in the table when the user presses the submit button.  I know I am missing something so easy, can someone point me in the right direction.

Here is the code I have tried.
RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext();
 
 
            PROVIDER_REFERRAL_QUEUE myProviderReferralQueue = new PROVIDER_REFERRAL_QUEUE();
 
            myProviderReferralQueue.DateFirstTryForAppt = DateTime.Today;
            lblFirstAttemptDate.Text = Convert.ToString(DateTime.Today);
 
            dcRadRelay.PROVIDER_REFERRAL_QUEUEs.UpdateonSubmit;---<--Just A Shot:)
            dcRadRelay.SubmitChanges();

Open in new window

0
kwh3856
Asked:
kwh3856
  • 5
  • 2
1 Solution
 
kwh3856Author Commented:
Problem solved needed to lookup record first and then submit the changes.
0
 
Fernando SotoRetiredCommented:
Hi Kenny;

With this line of code you create an record of type PROVIDER_REFERRAL_QUEUE:
PROVIDER_REFERRAL_QUEUE myProviderReferralQueue = new PROVIDER_REFERRAL_QUEUE();

Then you assigned a value to that new record with this line of code.
myProviderReferralQueue.DateFirstTryForAppt = DateTime.Today;  

Then you mark it for Update with this line of code:
dcRadRelay.PROVIDER_REFERRAL_QUEUEs.UpdateonSubmit;

You are not updating a record but creating one.

If you want to update a record you need to get a reference to the record to be updated, using a Linq query possibly, and then modify the field and then UpdateOnSubmit.

Hope that helps.

Fernando
0
 
kwh3856Author Commented:
Fernando,
I thought I had it but the field never gets updated now.  I have no errors that pop up....just no data:)
Can you show me where I made my mistake?
Thanks
Kenny
 

protected void btnAttempt1_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)
        {
            RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext();
 
 
            PROVIDER_REFERRAL_QUEUE myProviderReferralQueue = new PROVIDER_REFERRAL_QUEUE();
 
            string MPI;
            MPI = Session.Contents["MPI"].ToString();
            Guid ConvertedMPI = new Guid(MPI);
            
            var ReferralsResult = from referralsdata in dcRadRelay.PROVIDER_REFERRAL_QUEUEs
                                  where referralsdata.MPI == ConvertedMPI
                               select new { referralsdata };
 
            int ReferralRecCount = Convert.ToInt32(ReferralsResult.Count());    // <===== Added this line to get total count here
 
            if (ReferralRecCount == 0)                    // <===== Changed this line so that the query does not get executed again
            {
                // No Referral record found
            }
            else
            {
                foreach (var ReferralsResultRecord in ReferralsResult)
                {
                    myProviderReferralQueue.DateFirstTryForAppt = DateTime.Today;
                    lblFirstAttemptDate.Text = Convert.ToString(DateTime.Today);
                    
                    dcRadRelay.SubmitChanges();
                }
            }
 
        }

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kwh3856Author Commented:
Ooohhh....I think I understand your comment now.  I will try a few things and let you know.
0
 
kwh3856Author Commented:
That was exactly it.  Here is my correct code:
 
 

protected void btnAttempt1_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)
        {
            RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext();
 
 
            string MPI;
            MPI = Session.Contents["MPI"].ToString();
            Guid ConvertedMPI = new Guid(MPI);
            
            var ReferralsResult = from referralsdata in dcRadRelay.PROVIDER_REFERRAL_QUEUEs
                                  where referralsdata.MPI == ConvertedMPI
                               select new { referralsdata };
 
            int ReferralRecCount = Convert.ToInt32(ReferralsResult.Count());    // <===== Added this line to get total count here
 
            if (ReferralRecCount == 0)                    // <===== Changed this line so that the query does not get executed again
            {
                // No Referral record found
            }
            else
            {
                foreach (var ReferralsResultRecord in ReferralsResult)
                {
                    
                    ReferralsResultRecord.referralsdata.DateFirstTryForAppt = DateTime.Today;
                    lblFirstAttemptDate.Text = Convert.ToString(DateTime.Today);
                    
                    dcRadRelay.SubmitChanges();
                }
            }
 
        }

Open in new window

0
 
kwh3856Author Commented:
AWESOME!!!!
0
 
Fernando SotoRetiredCommented:
Hi Kenny;

Your last post looks correct to me.

Fernando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now