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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Delete a row from dataset using delete method???

Delete a row from dataset using delete method???

Scheduled Pinned Locked Moved C#
csharpdatabasexmlhelptutorial
4 Posts 3 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.
  • S Offline
    S Offline
    SureshRocks
    wrote on last edited by
    #1

    Hi All, I am new to C# programming with ADO.NET. I tried to delete the specific row but it is not getting affected in the database table. however when i wrote to a XML file, the record seems to be deleted.

    SqlDataAdapter da = new SqlDataAdapter("select * from details", con);
    DataSet ds = new DataSet();
    da.Fill(ds, "details");
    DataRow row = ds.Tables["details"].Rows[0];
    if (row["Name"].ToString() == fi.Name)
    {
    ds.Tables["details"].Rows[0].Delete();
    da.Update(ds.Tables["details"]);
    }
    ds.AcceptChanges();

    Can any one help me out with an example(C#) for better understanding. Thanks in advance.. Suresh.

    G P 2 Replies Last reply
    0
    • S SureshRocks

      Hi All, I am new to C# programming with ADO.NET. I tried to delete the specific row but it is not getting affected in the database table. however when i wrote to a XML file, the record seems to be deleted.

      SqlDataAdapter da = new SqlDataAdapter("select * from details", con);
      DataSet ds = new DataSet();
      da.Fill(ds, "details");
      DataRow row = ds.Tables["details"].Rows[0];
      if (row["Name"].ToString() == fi.Name)
      {
      ds.Tables["details"].Rows[0].Delete();
      da.Update(ds.Tables["details"]);
      }
      ds.AcceptChanges();

      Can any one help me out with an example(C#) for better understanding. Thanks in advance.. Suresh.

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Call the Update method

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      1 Reply Last reply
      0
      • S SureshRocks

        Hi All, I am new to C# programming with ADO.NET. I tried to delete the specific row but it is not getting affected in the database table. however when i wrote to a XML file, the record seems to be deleted.

        SqlDataAdapter da = new SqlDataAdapter("select * from details", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "details");
        DataRow row = ds.Tables["details"].Rows[0];
        if (row["Name"].ToString() == fi.Name)
        {
        ds.Tables["details"].Rows[0].Delete();
        da.Update(ds.Tables["details"]);
        }
        ds.AcceptChanges();

        Can any one help me out with an example(C#) for better understanding. Thanks in advance.. Suresh.

        P Offline
        P Offline
        PC Player
        wrote on last edited by
        #3

        Hi, It seems to be you are trying to delete First Row (Rows[0]), Which you don't want. You have to get specific object of that row and then use Delete command. After that you can update by useing DataAdapter to make permenent delete underling Database. Here is a code which might Help.

        foreach (Datarow dr in ds.tables[Customer].rows)
        {
        // Match condition for specific record
        Dr.delete();
        break;

        }

        da.update(ds);

        Hope it will help Thanks

        Ali Zishan London

        S 1 Reply Last reply
        0
        • P PC Player

          Hi, It seems to be you are trying to delete First Row (Rows[0]), Which you don't want. You have to get specific object of that row and then use Delete command. After that you can update by useing DataAdapter to make permenent delete underling Database. Here is a code which might Help.

          foreach (Datarow dr in ds.tables[Customer].rows)
          {
          // Match condition for specific record
          Dr.delete();
          break;

          }

          da.update(ds);

          Hope it will help Thanks

          Ali Zishan London

          S Offline
          S Offline
          SureshRocks
          wrote on last edited by
          #4

          Hi, Thanks a lot!!! It's working. Thanks once again, Suresh kumar palleti, India.

          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