Database updates in LINQ

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?anVsaW8=?=

    Database updates in LINQ

    I am trying to use Update to save changes made on two DataGridView's to two
    tables (Posts & PostDetails) with a FK relationship. I say

    private void bUpdate_Click(o bject sender, EventArgs e) {
    try {

    CustomerDataSet TableAdapters.T ableAdapterMana ger taManager = new
    CustomerDataSet TableAdapters.T ableAdapterMana ger();
    taManager.Posts TableAdapter = postsTableAdapt er;
    taManager.PostD etailsTableAdap ter = postDetailsTabl eAdapter;
    postsBindingSou rce.EndEdit();
    postsDetailsBin dingSource.EndE dit();
    taManager.Updat eAll(customerDa taSet);
    }
    catch (System.Excepti on ex) {
    MessageBox.Show (ex.Message.ToS tring());
    }

    }

    It doesn't work. Note:
    1. Changes (just DataGridView edits to existing records) don;t show in the
    databse.
    2. It doen't raise an exception.
    3. CustomerDataSet (in UpdateAll() line) contains the new values.

    Can you help?

    Thanks


  • Cowboy \(Gregory A. Beamer\)

    #2
    Re: Database updates in LINQ

    You realize what you have here is not LINQ, right?

    As for the problem, try firing AcceptChanges on the DataSet prior to firing
    off UpdateAll on the TableAdapter.

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    Subscribe to my blog


    or just read it:


    *************** *************** **************
    | Think outside the box! |
    *************** *************** **************
    "julio" <julio@discussi ons.microsoft.c omwrote in message
    news:F41ADCB3-3C80-4389-B67D-448B460BD09B@mi crosoft.com...
    >I am trying to use Update to save changes made on two DataGridView's to two
    tables (Posts & PostDetails) with a FK relationship. I say
    >
    private void bUpdate_Click(o bject sender, EventArgs e) {
    try {
    >
    CustomerDataSet TableAdapters.T ableAdapterMana ger taManager = new
    CustomerDataSet TableAdapters.T ableAdapterMana ger();
    taManager.Posts TableAdapter = postsTableAdapt er;
    taManager.PostD etailsTableAdap ter = postDetailsTabl eAdapter;
    postsBindingSou rce.EndEdit();
    postsDetailsBin dingSource.EndE dit();
    taManager.Updat eAll(customerDa taSet);
    }
    catch (System.Excepti on ex) {
    MessageBox.Show (ex.Message.ToS tring());
    }
    >
    }
    >
    It doesn't work. Note:
    1. Changes (just DataGridView edits to existing records) don;t show in the
    databse.
    2. It doen't raise an exception.
    3. CustomerDataSet (in UpdateAll() line) contains the new values.
    >
    Can you help?
    >
    Thanks
    >
    >

    Comment

    • =?Utf-8?B?anVsaW8=?=

      #3
      Re: Database updates in LINQ

      Thanks for your answer.

      1) Unfortunately, AcceptChanges doesn't fix the problem.

      1a) ANyway, why would this work when the dataset already contains the
      changes, as verified during debugging???

      2) Yes, I realize that this is not link, but then again, I was (naively)
      thinking that DataContext would have an Update method, but apparently it
      doesn't, so at this point I don't have anything that works, Linq or
      otherwise.

      3) BTW the DataSet has the hierarchical updates member set to true.

      JK

      "Cowboy (Gregory A. Beamer)" wrote:
      You realize what you have here is not LINQ, right?
      >
      As for the problem, try firing AcceptChanges on the DataSet prior to firing
      off UpdateAll on the TableAdapter.
      >
      --
      Gregory A. Beamer
      MVP, MCP: +I, SE, SD, DBA
      >
      Subscribe to my blog

      >
      or just read it:

      >
      *************** *************** **************
      | Think outside the box! |
      *************** *************** **************
      "julio" <julio@discussi ons.microsoft.c omwrote in message
      news:F41ADCB3-3C80-4389-B67D-448B460BD09B@mi crosoft.com...
      I am trying to use Update to save changes made on two DataGridView's to two
      tables (Posts & PostDetails) with a FK relationship. I say

      private void bUpdate_Click(o bject sender, EventArgs e) {
      try {

      CustomerDataSet TableAdapters.T ableAdapterMana ger taManager = new
      CustomerDataSet TableAdapters.T ableAdapterMana ger();
      taManager.Posts TableAdapter = postsTableAdapt er;
      taManager.PostD etailsTableAdap ter = postDetailsTabl eAdapter;
      postsBindingSou rce.EndEdit();
      postsDetailsBin dingSource.EndE dit();
      taManager.Updat eAll(customerDa taSet);
      }
      catch (System.Excepti on ex) {
      MessageBox.Show (ex.Message.ToS tring());
      }

      }

      It doesn't work. Note:
      1. Changes (just DataGridView edits to existing records) don;t show in the
      databse.
      2. It doen't raise an exception.
      3. CustomerDataSet (in UpdateAll() line) contains the new values.

      Can you help?

      Thanks
      >
      >

      Comment

      Working...