OdbcDataAdapter update

kromax

Member
Joined
Feb 21, 2008
Messages
7
Hi,
I have a listview filled with a table from database with:
Private Sub FillList ()
....
....
SQL = "SELECT * FROM Voti"
dataSetVoti = New DataSet()
mioDataAdapter = New OdbcDataAdapter(SQL, dbConn)
mioDataAdapter.Fill(dataSetVoti, "Voti")
For Each resDataRow In dataSetVoti.Tables("Voti").Rows
lstItem = ListView1.Items.Add(resDataRow("Voti"))
.....
Next
.....
.....
End Sub

Then if I Update the table with:

Dim cmdVoti As OdbcCommand
Dim dbWriter As OdbcDataReader
SQL = "UPDATE Voti SET Voti = " & votiToAdd & " WHERE Codice = " & CLng(lvi.SubItems(4).Text)
cmdVoti = New OdbcCommand(SQL, dbAccr)
dbWriter = cmdVoti.ExecuteReader
dbWriter.Close()

and then call FillList ()
the table in database is updated but I do not see any changes in listview until I perform another Update and see the changes for the previous record updated and not for the last one or I have to close the form and re-open it to see the updated records.
Which is the mistake?
Thank you in advance.
 
Thank you PlausiblyDamp.
Unfortunely I Cant understand your replay probably due to my english. Im italian. Could you please expose your replay in a different way, possibly with one or two lines of code?
Thank you.
 
Nothing to do with your English - more to me not reading the question properly ;)

When you are doing the update try
Code:
Dim cmdVoti As OdbcCommand
SQL = "UPDATE Voti SET Voti = " & votiToAdd & " WHERE Codice = " & CLng(lvi.SubItems(4).Text)
cmdVoti = New OdbcCommand(SQL, dbAccr)
cmdVoti.ExecuteNonQuery()
 
Ive tried the code you post but nothing happened.
The problem still continue.
Even if Ive solved the problem writing new value directly into the listview to show to user the change, Id like to solve the problem in smarter way.
 
kromax:

You have to do 2 updates: Update your SQL database, then also update your local copy of the dataset.

I am no expert with databases, so this may be worded incorrectly; however, I had this same problem for many days. The solution was to update the SQL table; if that was successful, update my local copy of the data in the dataset.

I hope this is easy to understand in Itally.

If my logic is flawed, maybe PlausiblyDamp will step in to explain it better.
 
Back
Top