Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TableAdapter.Update() problem.

TableAdapter.Update() problem.

Scheduled Pinned Locked Moved C#
helpdatabasetutorialquestionannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hdv212
    wrote on last edited by
    #1

    hi in my solution, i created a table adapter and set select,insert,update,delete actions to my own stored procedures, then for add row, write the following code :

    FrmCategory frm = new FrmCategory(false, false);
    DsStack.CategoriesRow newRow = this.dt.NewCategoriesRow();
    Session.SaveInSession("newCategory", newRow);
    if (frm.ShowDialog() == DialogResult.OK)
    {
    newRow = Session.LoadFromSession("newCategory") as DsStack.CategoriesRow;
    this.dt.Rows.Add(newRow);
    this.adapter.Update(this.dt); // error occured in this line
    }

    When my table in database is empty : the first row add to table successfully, but the second row has not been add to database and the following error has shown me : **Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.** where does my problem and how to solve it ? thanks

    S A 2 Replies Last reply
    0
    • H hdv212

      hi in my solution, i created a table adapter and set select,insert,update,delete actions to my own stored procedures, then for add row, write the following code :

      FrmCategory frm = new FrmCategory(false, false);
      DsStack.CategoriesRow newRow = this.dt.NewCategoriesRow();
      Session.SaveInSession("newCategory", newRow);
      if (frm.ShowDialog() == DialogResult.OK)
      {
      newRow = Session.LoadFromSession("newCategory") as DsStack.CategoriesRow;
      this.dt.Rows.Add(newRow);
      this.adapter.Update(this.dt); // error occured in this line
      }

      When my table in database is empty : the first row add to table successfully, but the second row has not been add to database and the following error has shown me : **Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.** where does my problem and how to solve it ? thanks

      S Offline
      S Offline
      Shorgov
      wrote on last edited by
      #2

      check your stored procedures!

      Strahil Shorgov

      1 Reply Last reply
      0
      • H hdv212

        hi in my solution, i created a table adapter and set select,insert,update,delete actions to my own stored procedures, then for add row, write the following code :

        FrmCategory frm = new FrmCategory(false, false);
        DsStack.CategoriesRow newRow = this.dt.NewCategoriesRow();
        Session.SaveInSession("newCategory", newRow);
        if (frm.ShowDialog() == DialogResult.OK)
        {
        newRow = Session.LoadFromSession("newCategory") as DsStack.CategoriesRow;
        this.dt.Rows.Add(newRow);
        this.adapter.Update(this.dt); // error occured in this line
        }

        When my table in database is empty : the first row add to table successfully, but the second row has not been add to database and the following error has shown me : **Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.** where does my problem and how to solve it ? thanks

        A Offline
        A Offline
        alex almeida
        wrote on last edited by
        #3

        Your Update method waiting for 1 record to be updated, but your update sp doesn't update any row. Check you sp manually, sent the same values by parameter and watch the results.

        H 1 Reply Last reply
        0
        • A alex almeida

          Your Update method waiting for 1 record to be updated, but your update sp doesn't update any row. Check you sp manually, sent the same values by parameter and watch the results.

          H Offline
          H Offline
          hdv212
          wrote on last edited by
          #4

          thanks for replies my sp code is :

          Create Procedure [dbo].[sp_Categories_Insert]
          @categoryName nvarchar(30),
          @description nvarchar(400)
          As
          Begin
          Insert Into Categories
          ([categoryName],[description])
          Values
          (@categoryName,@description)

          Declare @ReferenceID int
          Select @ReferenceID = @@IDENTITY
          Return @ReferenceID
          

          End

          do i change sp code ?

          A 1 Reply Last reply
          0
          • H hdv212

            thanks for replies my sp code is :

            Create Procedure [dbo].[sp_Categories_Insert]
            @categoryName nvarchar(30),
            @description nvarchar(400)
            As
            Begin
            Insert Into Categories
            ([categoryName],[description])
            Values
            (@categoryName,@description)

            Declare @ReferenceID int
            Select @ReferenceID = @@IDENTITY
            Return @ReferenceID
            

            End

            do i change sp code ?

            A Offline
            A Offline
            alex almeida
            wrote on last edited by
            #5

            When You run this proc, what the value of @ReferenceID?

            H 1 Reply Last reply
            0
            • A alex almeida

              When You run this proc, what the value of @ReferenceID?

              H Offline
              H Offline
              hdv212
              wrote on last edited by
              #6

              Hi alex the ReferenceID is PK of Inserted Row

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups