Problem with refill of listview after removal in database
-
Hi I have a listview with items. I select, for instance 2 items for removal. I run my code to remove in database, wich work just correct. Then i run my method for fill, in a class, to refill the listview from database. In the case where i selected 2 items only 1 disappered from the listview, the other is still showing. If i select 1 item, that one is still showing after the fill. I do not understand what happens. I rather new in C# but i have done the same in VB.NET and FoxPro 9.0 and i have no problems. Here is the code. Anybody that can tip me about whats wrong ? if (result == DialogResult.OK) { clsReadKatalog clsReadKatalog; clsReadKatalog = new clsReadKatalog(); foreach (int idx in this.Katalog.SelectedIndices) { String xid = this.Katalog.Items[idx].SubItems[5].Text; int tabortid = this.Katalog.Items[idx].Index; clsReadKatalog.TaBortPost(xid); // DELETE FROM DATABASE } String urval = null; urval = "SELECT * FROM pwd WHERE ownid=" + "'" + this.GlobalAnvändare + "'" + " AND posttyp='1'"; OdbcDataReader Reader = clsReadKatalog.LäsKatalog(urval); if (Reader.HasRows) { clsReadKatalog.FyllKatalog(Reader, this.Katalog); // REFILL FROM DATABASE } Here is the code for fill listview: This is the same method i run the first time, to fill the listview, before i make my selection for remove, and then it pick right from database. public void FyllKatalog(OdbcDataReader Reader,ListView Lista) { Lista.Items.Clear(); int x=0; while (Reader.Read()) { Lista.Items.Add(Convert.ToString(Reader["beskr"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["anv"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["pwd"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["privatekey"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["vektor"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["id"])); x += 1; } Reader.Close(); } With Kind Regards Heino Heino Nurmik
-
Hi I have a listview with items. I select, for instance 2 items for removal. I run my code to remove in database, wich work just correct. Then i run my method for fill, in a class, to refill the listview from database. In the case where i selected 2 items only 1 disappered from the listview, the other is still showing. If i select 1 item, that one is still showing after the fill. I do not understand what happens. I rather new in C# but i have done the same in VB.NET and FoxPro 9.0 and i have no problems. Here is the code. Anybody that can tip me about whats wrong ? if (result == DialogResult.OK) { clsReadKatalog clsReadKatalog; clsReadKatalog = new clsReadKatalog(); foreach (int idx in this.Katalog.SelectedIndices) { String xid = this.Katalog.Items[idx].SubItems[5].Text; int tabortid = this.Katalog.Items[idx].Index; clsReadKatalog.TaBortPost(xid); // DELETE FROM DATABASE } String urval = null; urval = "SELECT * FROM pwd WHERE ownid=" + "'" + this.GlobalAnvändare + "'" + " AND posttyp='1'"; OdbcDataReader Reader = clsReadKatalog.LäsKatalog(urval); if (Reader.HasRows) { clsReadKatalog.FyllKatalog(Reader, this.Katalog); // REFILL FROM DATABASE } Here is the code for fill listview: This is the same method i run the first time, to fill the listview, before i make my selection for remove, and then it pick right from database. public void FyllKatalog(OdbcDataReader Reader,ListView Lista) { Lista.Items.Clear(); int x=0; while (Reader.Read()) { Lista.Items.Add(Convert.ToString(Reader["beskr"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["anv"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["pwd"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["privatekey"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["vektor"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["id"])); x += 1; } Reader.Close(); } With Kind Regards Heino Heino Nurmik
henur wrote:
String xid = this.Katalog.Items[idx].SubItems[5].Text; int tabortid = this.Katalog.Items[idx].Index; clsReadKatalog.TaBortPost(xid); // DELETE FROM DATABASE
Wouldn't a proc that takes a collection of Ids to delete make more sense ? What is tabortid used for ?
henur wrote:
Lista.Items.Clear(); int x=0; while (Reader.Read()) { Lista.Items.Add(Convert.ToString(Reader["beskr"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["anv"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["pwd"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["privatekey"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["vektor"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["id"])); x += 1; } Reader.Close();
If this pulls out data you thought you deleted, then you can't possibly have deleted it. Unless the reader was created before something was deleted, but that doesn't seem possible, either.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
henur wrote:
String xid = this.Katalog.Items[idx].SubItems[5].Text; int tabortid = this.Katalog.Items[idx].Index; clsReadKatalog.TaBortPost(xid); // DELETE FROM DATABASE
Wouldn't a proc that takes a collection of Ids to delete make more sense ? What is tabortid used for ?
henur wrote:
Lista.Items.Clear(); int x=0; while (Reader.Read()) { Lista.Items.Add(Convert.ToString(Reader["beskr"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["anv"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["pwd"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["privatekey"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["vektor"])); Lista.Items[x].SubItems.Add(Convert.ToString(Reader["id"])); x += 1; } Reader.Close();
If this pulls out data you thought you deleted, then you can't possibly have deleted it. Unless the reader was created before something was deleted, but that doesn't seem possible, either.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Ok , "tabortid" is just a remaining after that i removed the items by the selected items.index. But about the deletion, yes they are removed in the database. In debug-mode i do a hold, and then open the access-database and check the table....and they are gone. And really, i have a similar problem in an other place. When i add a item, when i refill the listview the new one is not added to the view, but be sure! ...it is in the database. So...i don't get it!
-
Ok , "tabortid" is just a remaining after that i removed the items by the selected items.index. But about the deletion, yes they are removed in the database. In debug-mode i do a hold, and then open the access-database and check the table....and they are gone. And really, i have a similar problem in an other place. When i add a item, when i refill the listview the new one is not added to the view, but be sure! ...it is in the database. So...i don't get it!
What you're describing is not possible. If you delete a row, and refresh from the DB, the row will be gone, unless you don't clear the control first ( and I see, you did ). So, something else is going on here.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
What you're describing is not possible. If you delete a row, and refresh from the DB, the row will be gone, unless you don't clear the control first ( and I see, you did ). So, something else is going on here.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
That's true...something else.... :-) Well , i will go thru my code again and see if i can find anything that could cause my problem. As you said earlier "...if the reader is created before.." in some way the problem "feels" like that. So i will check that possibility. Heino