none
Get updated data by linq RRS feed

  • Question

  • Hello everyone

    I'm using Linq to select and update my data. My problem is when I update one record and then select it again, It doesn't show updated data since I close and reopen my program. I tried to close and open sqlconnection before selecting data , but still it doesn't work.

    Can anyone help me with this?

    Tuesday, August 14, 2012 9:37 AM

Answers

  • hello guys,

    My problem is solved in a strange way.I have a private variable of my classes file like DataAccess.sc . I just Removed it and then declared it in each function that I need.

    Thanks for your help.

    • Marked as answer by Alexander Sun Wednesday, August 15, 2012 9:20 AM
    Wednesday, August 15, 2012 9:12 AM

All replies

  • Please post your sample code. I hope Your LINQ query will get the data from cache or any tmp memory.

    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    Tuesday, August 14, 2012 12:10 PM
  • I have a table which is called CompBank:

    this is how I select it and how I update it. 

    ////////////////////////////////////

    publicList<CompBank> CompBankList(stringUser)

            {

    varp = froma indb.CompBanks

    joinb indb.Users     

    ona.UserID equalsb.UserID intog

    wherea.UserID == User

    selecta;

    returnp.OrderBy(a => a.CompYear).OrderBy(b => b.CompMonth).ToList();

            }

           

    ////////////////////////////////////////////

    publicvoidUpdateCompBank(CompBankc)

            {

                db.spUpdateInCompBank(c.UserID, c.CompMonth, c.CompYear, c.RemainedComp, c.Comp, c.UsedComp, c.Comments );

    try

                {

                    db.SubmitChanges();

                }

    catch(ChangeConflictException)

               {

                }

            }

    also I use a static variable of my datacontext in my form.

    staticData.RossabDBDataContextdb = newData.RossabDBDataContext();

    but after I use update and then I refresh data by calling CompBankList , It doesn't have updated data until I restard my program.


    Tuesday, August 14, 2012 1:13 PM
  • Remove the static and try

    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    Tuesday, August 14, 2012 1:33 PM
  • It doesn't work yet.
    Tuesday, August 14, 2012 3:02 PM
  • Hi Mohit,

    Did you use this method to refresh DataContext? If not, please try refresh DataContext first: http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.refresh.aspx

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 15, 2012 2:13 AM
  • hello guys,

    My problem is solved in a strange way.I have a private variable of my classes file like DataAccess.sc . I just Removed it and then declared it in each function that I need.

    Thanks for your help.

    • Marked as answer by Alexander Sun Wednesday, August 15, 2012 9:20 AM
    Wednesday, August 15, 2012 9:12 AM