Delete a row in a dataset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VG9yZW4gVmFsb25l?=

    Delete a row in a dataset

    I have a simple datatable in a dataset and cannot figure out how to delete
    the current row in the dataset/table. I have been able to hard code the
    current row value to a 1, and that works deleting just the first record.

    ds.Tables["inquiry_da ta"].Rows[1].Delete();

    How do i get the current row being displayed?
  • JDeats

    #2
    Re: Delete a row in a dataset

    On Aug 25, 6:44 pm, Toren Valone
    <TorenVal...@di scussions.micro soft.comwrote:
    I have a simple datatable in a dataset and cannot figure out how to delete
    the current row in the dataset/table. I have been able to hard code the
    current row value to a 1, and that works deleting just the first record.
    >
    ds.Tables["inquiry_da ta"].Rows[1].Delete();
    >
    How do i get the current row being displayed?
    Current row being displayed would be relative to the container object
    (i.e. dataGridView) that's being used to display the DataTable
    content, so you would need to fetch that value from the container. To
    remove a row from a DataTable use the Remove or RemoveAt method off of
    the Rows collection, off of the DataTable instance.

    dt.Rows.Remove( myRow);


    Comment

    • Ken Foskey

      #3
      Re: Delete a row in a dataset

      On Mon, 25 Aug 2008 16:44:06 -0700, Toren Valone wrote:
      I have a simple datatable in a dataset and cannot figure out how to
      delete the current row in the dataset/table. I have been able to hard
      code the current row value to a 1, and that works deleting just the
      first record.
      >
      ds.Tables["inquiry_da ta"].Rows[1].Delete();
      >
      How do i get the current row being displayed?
      You are deleting the second record, not the first. [0] would be the first.

      You delete using the binding source. I think the following is correct...

      ((DataRowView)b indingSource.Cu rrent).Delete() ;

      Comment

      • =?Utf-8?B?VG9yZW4gVmFsb25l?=

        #4
        Re: Delete a row in a dataset

        Thanks, I ended up coding this and it works great.

        int current = this.BindingCon text[ds, "inquiry_da ta"].Position;

        ds.Tables["vr_record"].Rows[current].Delete();

        ds.AcceptChange s();
        ds.WriteXml("vr database.xml");

        "Ken Foskey" wrote:
        On Mon, 25 Aug 2008 16:44:06 -0700, Toren Valone wrote:
        >
        I have a simple datatable in a dataset and cannot figure out how to
        delete the current row in the dataset/table. I have been able to hard
        code the current row value to a 1, and that works deleting just the
        first record.

        ds.Tables["inquiry_da ta"].Rows[1].Delete();

        How do i get the current row being displayed?
        >
        You are deleting the second record, not the first. [0] would be the first.
        >
        You delete using the binding source. I think the following is correct...
        >
        ((DataRowView)b indingSource.Cu rrent).Delete() ;
        >

        Comment

        Working...