dataSet.HasChanges returns false after dataSet is modified

P

pplppp

I have a windows form application getting data from an access database
file using dataadapters, here are the objects I have:
mydataset - mydataTable - mydataview
I use the dataview to find the records I want and bind it to a windows
form control.
anyway, my problem is, when I use the following code to remove a
record:

DataRow[] rows = myDataTable.Select("key="+key);
myDataTable.RemoveDataRow(rows[0]);

then I call myDataSet.HasChanges(), it returns false?! GetChanges()
return null as well. but if I replace the code with

int index = myDataView.Find(key);
myDataView.Delete(index);

then myDataSet.HasChanges() return true

can anyone tell me why I can't delete the rows from the datatable? or
did I do something wrong?

thanks
 
W

William \(Bill\) Vaughn

RemoveDataRow is not a method that I've seen. Is it one you wrote yourself?
When you apply the Remove method on a DataTable Row, you physically remove
the DataRow from the Rows collection. As far as ADO.NET is concerned the row
never existed. HasChanges indicates that there are changes in the Rows
collection that need to be posted to the server. If you want to delete a row
on the server (using the Update method), you need to use the Delete method
on the row and then call Update on the DataAdapter. This is all explained
in detail in my book.

hth

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
W

William Ryan

My IDE doesn't have RemoveDataRow, but if you use
datatable.rows.delete(dr(0)) I think that should do it for you...

HTH,

Bill
 
P

pplppp

oh sorry I didn't say it clearly in my original question. I am working
with a typed dataset, so VS.NET generated that Remove[TableName]Row
for me.. and that's the function I called to remove the row.
but anyway I think you've answered my question... remove removes the
row rather than marking it as deleted.. so that's why the HasChanges
method doesn't know that the dataTable has been modified.
thanks
 

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