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. Visual Basic
  4. How to update a table

How to update a table

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestionannouncement
7 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.
  • C Offline
    C Offline
    cstrader232
    wrote on last edited by
    #1

    I guess I thought it would be easy to update a table, but evidently my code is incorrect. This code keeps producing this error: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. whenever I make a change in the table and then press button1. could anyone please explain why? tia Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TickersTableAdapter.Fill(Me.DataSet1.Tickers) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.TickersTableAdapter.Update(Me.DataSet1.Tickers) Me.DataSet1.AcceptChanges() End Sub End Class

    N D 2 Replies Last reply
    0
    • C cstrader232

      I guess I thought it would be easy to update a table, but evidently my code is incorrect. This code keeps producing this error: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. whenever I make a change in the table and then press button1. could anyone please explain why? tia Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TickersTableAdapter.Fill(Me.DataSet1.Tickers) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.TickersTableAdapter.Update(Me.DataSet1.Tickers) Me.DataSet1.AcceptChanges() End Sub End Class

      N Offline
      N Offline
      Nikhil Bandekar
      wrote on last edited by
      #2

      hii One simple way to solve this problem is to add atleast one record in the data base as you aspect it to be. or else just try to fill the primary record of the table with your value. just try it and reply bye

      Nikhil Bandekar Mumbai, India

      C 1 Reply Last reply
      0
      • N Nikhil Bandekar

        hii One simple way to solve this problem is to add atleast one record in the data base as you aspect it to be. or else just try to fill the primary record of the table with your value. just try it and reply bye

        Nikhil Bandekar Mumbai, India

        C Offline
        C Offline
        cstrader232
        wrote on last edited by
        #3

        Hi Nikhil: Yes, you are right that if I add a new row to the table then everything is OK. But how can update the table WITHOUT adding a new row? thanks!

        1 Reply Last reply
        0
        • C cstrader232

          I guess I thought it would be easy to update a table, but evidently my code is incorrect. This code keeps producing this error: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. whenever I make a change in the table and then press button1. could anyone please explain why? tia Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TickersTableAdapter.Fill(Me.DataSet1.Tickers) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.TickersTableAdapter.Update(Me.DataSet1.Tickers) Me.DataSet1.AcceptChanges() End Sub End Class

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          What does your SELECT SQL statement look like? Does it return a Primary Key column? (BTW: This is a MUST HAVE!) What does the UPDATE SQL statement look like or are you using a CommandBuilder to generate it?

          Dave Kreskowiak Microsoft MVP - Visual Basic

          C 1 Reply Last reply
          0
          • D Dave Kreskowiak

            What does your SELECT SQL statement look like? Does it return a Primary Key column? (BTW: This is a MUST HAVE!) What does the UPDATE SQL statement look like or are you using a CommandBuilder to generate it?

            Dave Kreskowiak Microsoft MVP - Visual Basic

            C Offline
            C Offline
            cstrader232
            wrote on last edited by
            #5

            Thanks Dave, that was the problem. The table had no primary key! Happy weekend! chuck

            C 1 Reply Last reply
            0
            • C cstrader232

              Thanks Dave, that was the problem. The table had no primary key! Happy weekend! chuck

              C Offline
              C Offline
              cstrader232
              wrote on last edited by
              #6

              ...but why couldn't the error message say something like "table has no primary key!" or "$%()*&$)(*&%)(*#&$ (stuff that I can't understand): this error might be caused if the table has no primary key" Just a thought... BTW, I love vb.net despite these small issues. Didn't Gates say something about betting the company on .net. It's a good bet assuming there's enough people out there still writing code! c

              D 1 Reply Last reply
              0
              • C cstrader232

                ...but why couldn't the error message say something like "table has no primary key!" or "$%()*&$)(*&%)(*#&$ (stuff that I can't understand): this error might be caused if the table has no primary key" Just a thought... BTW, I love vb.net despite these small issues. Didn't Gates say something about betting the company on .net. It's a good bet assuming there's enough people out there still writing code! c

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Because there's about a dozen reasons why an Update would affect 0 records. The problem has nothing to do with VB.NET. ADO.NET is what is reporting the error back to your code, but even then, it can't possibly know what caused it. It's just the SQL statement that failed, in the context of the database that it was used.

                Dave Kreskowiak Microsoft MVP - Visual Basic

                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