kromax Posted May 2, 2008 Posted May 2, 2008 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. Quote
Administrators PlausiblyDamp Posted May 5, 2008 Administrators Posted May 5, 2008 Could you not have the UpdateCommand also select the new information back? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
kromax Posted May 5, 2008 Author Posted May 5, 2008 Thank you PlausiblyDamp. Unfortunely I Can't understand your replay probably due to my english. I'm italian. Could you please expose your replay in a different way, possibly with one or two lines of code? Thank you. Quote
Administrators PlausiblyDamp Posted May 5, 2008 Administrators Posted May 5, 2008 Nothing to do with your English - more to me not reading the question properly ;) When you are doing the update try Dim cmdVoti As OdbcCommand SQL = "UPDATE Voti SET Voti = " & votiToAdd & " WHERE Codice = " & CLng(lvi.SubItems(4).Text) cmdVoti = New OdbcCommand(SQL, dbAccr) cmdVoti.ExecuteNonQuery() Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
kromax Posted May 7, 2008 Author Posted May 7, 2008 I've tried the code you post but nothing happened. The problem still continue. Even if I've solved the problem writing new value directly into the listview to show to user the change, I'd like to solve the problem in smarter way. Quote
joe_pool_is Posted May 8, 2008 Posted May 8, 2008 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. Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.