Updating database via dgv doesn't work in some cases

  • Thread starter Thread starter Kevin993
  • Start date Start date
K

Kevin993

Guest
Greetings,

I'm facing a wired issue.

I use the code below to populate a dgv :


Public adapter As OleDbDataAdapter
Public dt As DataTable

Dim conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\datasource.mdb;Persist Security Info=False;")


Sub loadINFO()

conn.open()
dt = New DataTable()
Dim selectSql = "select * from Table1 "
adapter = New OleDbDataAdapter(selectSql, conn)
adapter.Fill(dt)
dgv.DataSource = dt

conn.close()


End Sub


Then I change some values in the cells programmatically (via looping through dgv cells and if conditions true , some changes happen)

After changing values in some cells, I can see those changes in dgv (sure that some of its cells now have new values).

Then I call the following sub :


Sub UpdateDatabase()

Dim scb = New OleDbCommandBuilder(adapter)
adapter.Update(dt)

End sub



Sometimes it doesn't work and sometimes it works!

I understood that if I'm about to change first row's cells and then call for updateDatabase , it doesn't work. I have to manually click on dgv (clicking on any other cells or rows) and then call for updateDatabase, then it seems to work.

I guess this issue is only about the first row. I tested other rows and it seems to work.

What could be the reason? How can i make sure that in future updating database works regardless of clicking dgv or ... .

P.S I need to make my dgv invisible, and disabled (making sure that users do not manually reach and edit values)

Continue reading...
 
Back
Top