How to update a table
-
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
-
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
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
-
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
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!
-
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
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
-
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
Thanks Dave, that was the problem. The table had no primary key! Happy weekend! chuck
-
Thanks Dave, that was the problem. The table had no primary key! Happy weekend! chuck
...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
-
...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
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