LINQ - Databinding questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Tallent

    LINQ - Databinding questions

    I have a form I'm playing around with that has some text boxes on it. I am
    using SQL 2005 for my database.
    I have a single table which I have created an object entity for. Customer

    On the form I set the DataBindings Text value to "customerBindin gSource -
    CompanyName" on one of the textboxes.
    The customerBinding Source was generated by the IDE and is pointing to the
    Customer entity I created earlier. The CompanyName is a field within the
    entity and underlying table.

    During runtime I am using the follow code:

    //----------------------------------------------------------------------------------
    // This line is where my problem is.

    this.CDC = new CustSiteDataCon text(ConnString );


    // Retreive customer record


    var queryCust = from cust in CDC.Customers

    where (cust.CustomerI D == 100) && (cust.CompanyID == 5)

    select cust;

    this.customerBi ndingSource.Dat aSource = queryCust;

    //----------------------------------------------------------------------------------

    This works great, it reads the data in, I can make modifications and when I
    click my button to save I execute:

    this.CDC.Submit Changes();

    If the user wishes to abandon the changes, the idea is they can click a
    button to do so. This code appears to work however I have to recreate a
    new instance of the CustSiteDataCon text for this to work.

    In prior attempts I was looking at the refresh method, but I could not
    figure out how to write it.
    // CDC.Refresh(Sys tem.Data.Linq.R efreshMode.Over writeCurrentVal ues);

    Is the method I am using above the best/only way to implement "abandon"
    changes ?



    Thanks,

    Dan


  • Marc Gravell

    #2
    Re: LINQ - Databinding questions

    Largely, yes. Getting a fresh data-context is the safest way of
    ensuring you aren't keeping any abandoned changes. You shouldn't keep
    a data-context around for too long anyway; they are intended to be
    locally scoped, not last for the duration of an app.

    Marc

    Comment

    • Dan Tallent

      #3
      Re: LINQ - Databinding questions

      Thanks for the response. My idea was to only keep the DataContext while the
      user resides on that particular form. Its great to know I'm not completely
      lost.

      Thanks
      Dan



      "Marc Gravell" <marc.gravell@g mail.comwrote in message
      news:31335544-bf8a-4a50-9f80-970abaa52dd6@26 g2000hsk.google groups.com...
      Largely, yes. Getting a fresh data-context is the safest way of
      ensuring you aren't keeping any abandoned changes. You shouldn't keep
      a data-context around for too long anyway; they are intended to be
      locally scoped, not last for the duration of an app.
      >
      Marc

      Comment

      Working...