Delete a row in a dataset

T

Toren Valone

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_data"].Rows[1].Delete();

How do i get the current row being displayed?
 
J

JDeats

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_data"].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);
 
K

Ken Foskey

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_data"].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)bindingSource.Current).Delete();
 
T

Toren Valone

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

int current = this.BindingContext[ds, "inquiry_data"].Position;

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

ds.AcceptChanges();
ds.WriteXml("vrdatabase.xml");

Ken Foskey said:
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_data"].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)bindingSource.Current).Delete();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top