Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with refill of listview after removal in database

Problem with refill of listview after removal in database

Scheduled Pinned Locked Moved C#
csharpdatabasehelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    henur
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • H henur

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      H 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        H Offline
        H Offline
        henur
        wrote on last edited by
        #3

        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!

        C 1 Reply Last reply
        0
        • H henur

          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!

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          H 1 Reply Last reply
          0
          • C Christian Graus

            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 )

            H Offline
            H Offline
            henur
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups