Solved

save changes C# - LINQ - ASP.NET

Posted on 2013-01-11
2
321 Views
Last Modified: 2013-01-14
Consider this code for filling in the data for a record:

  string[] aflidsid = Session["afa_agentformlistidsid"].ToString().Split('-');
            
            using (AgentFormsDataContext dc = new AgentFormsDataContext())
            {
                getOneAgentForm = dc.AgentFormEdit_AgentForm_Get(Convert.ToInt32(aflidsid[0]), Convert.ToInt32(aflidsid[1])).ToList<Models.AgentFormEdit_AgentForm_GetResult>();                
            }     

            foreach (Models.AgentFormEdit_AgentForm_GetResult agentfield in getOneAgentForm)
            {
                ddlLookupFormType.LookupID = agentfield.FormTypeID;
                TextBoxSequence.Text = agentfield.Sequence.ToString();
                TextBoxFormName.Text = agentfield.FormName;
                TextBoxColist.Text = agentfield.ColistFlag.ToString();
                RadioButtonAcceptanceRequiredFalse.Checked = agentfield.AcceptanceReqd == true ?  false : true;
                RadioButtonAcceptanceRequiredTrue.Checked = !RadioButtonAcceptanceRequiredFalse.Checked;
                RadioButtonDuplicatesAllowedFalse.Checked = agentfield.DuplicatesAllowed == true ? false : true;
                RadioButtonDuplicatesAllowedTrue.Checked = !RadioButtonDuplicatesAllowedFalse.Checked;                
                TextBoxExternalLink.Text = agentfield.ExternalLink;
                TextBoxTaskCode.Text = agentfield.TaskCode;
             //   TextBoxAMFirm.Text = agentfield.AMFID.ToString();
             //   TextBoxClient.Text = agentfield.ClientID.ToString();
                ddlProducts.SelectedValue = agentfield.ProductID.ToString();
                RadioButtonActiveFalse.Checked = agentfield.Active == true ? false : true;
                RadioButtonActiveTrue.Checked = !RadioButtonActiveFalse.Checked;

                //ternary operator syntax example
                //int ystep = y0 < y1 ? 1 : -1;
            }         

Open in new window




How to I then save any changes using the same construct at a later time?

In other words:

Models.AgentFormEdit_AgentForm_GetResult

is how I get my data

so I need the analog:

Models.AgentFormEdit_AgentForm_Update?


I can write a stored procedure to do the update...not sure of the C# ( LINQ? ) syntax...
0
Comment
Question by:knowlton
2 Comments
 
LVL 18

Accepted Solution

by:
Gary Davis earned 500 total points
ID: 38770080
You can execute a stored proc out of the datacontext using ExecuteCommand() or if the SP is part of the AgentFormsDataContext, it will be available to call directly as a method of the context.

Alternatively, you could issue your dc.AgentFormEdit_AgentForm_Get() call to initialize the context with the data, update the fields in the loop similar to above (the datacontext will track the changed properties) and finally, call SubmitChanges().
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 38776361
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now