Solved

save changes C# - LINQ - ASP.NET

Posted on 2013-01-11
2
319 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

17 Experts available now in Live!

Get 1:1 Help Now