Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update of access db fails

Status
Not open for further replies.

lin73

Programmer
Feb 17, 2006
110
0
0
SE


Hi



When I try to update using the code below I get this error "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."




Imports System.Data
Imports System.Data.OleDb

Private Shared MyDataAdapter As OleDbDataAdapter
Private Shared MyDataSet As DataSet

Sub BindGrid()
Dim sqlStr As String = "SELECT * FROM tbl_Work"
Dim conn As OleDbConnection = New OleDbConnection(MyProviderString)
MyDataAdapter = New OleDbDataAdapter(sqlStr, conn)
MyDataSet = New DataSet
MyDataAdapter.Fill(MyDataSet, "tbl_Work")
Dim MyDataView As DataView = MyDataSet.Tables("tbl_Work").DefaultView
DataGridView1.DataSource = MyDataSet.Tables("tbl_Work").DefaultView
End Sub

Private Sub TabControl1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
BindGrid()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim myBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(MyDataAdapter)
myBuilder.GetUpdateCommand()
MyDataAdapter.UpdateCommand = myBuilder.GetUpdateCommand()
MyDataAdapter.Update(MyDataSet, "tbl_Work")
MyDataSet.AcceptChanges()
MsgBox("Updation is over")
End Sub







Am I missing something here?



Best Regards
 
Could be a problem with the data in your table. Have you tried setting upyour own update command and see if that works?

try doing a google search for more info.
 
Hi

If I add a update subroutine it works fine to update or add data, but not using the code in my example.
 
I would go with your own update command. If you know your works, stick with it.
 
Hi

Yes I would do that if I knew how I should access the datagridview's ID and all the other values that I changed and needs to be updated.
 
I use this to get the values changed in a datagridview
on the cellendedit event

rowid = (FoodGridView.Rows(e.RowIndex).Cells.Item(0).Value())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top