473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ADO.NET explanation of deleting rows from DB please?

Hi,

I want to delete rows from my database. So I download them to a
dataset, and then discover the following.

This does not work:

dataset["tablename"].Rows.Clear();
dataadapter.Update(dataset, "tablename");
This does work:

foreach (DataRow dr in dataset["tablename"].Rows)
{
dr.delete();
}
dataadapter.Update(dataset, "tablename");

I don't know enough about what's going on "underneath the hood" - why
doesn't the first one work?

Thanks for any info,

cdj

Oct 31 '06 #1
2 1886
The DataAdapter's Update Method relies on the RowState of each row in the
datatable to tell whether to perform an update, insert, or delete. Since in
the first case you've cleared out all the DataRows, it therefore has nothing
to do.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"sherifffruitfly" wrote:
Hi,

I want to delete rows from my database. So I download them to a
dataset, and then discover the following.

This does not work:

dataset["tablename"].Rows.Clear();
dataadapter.Update(dataset, "tablename");
This does work:

foreach (DataRow dr in dataset["tablename"].Rows)
{
dr.delete();
}
dataadapter.Update(dataset, "tablename");

I don't know enough about what's going on "underneath the hood" - why
doesn't the first one work?

Thanks for any info,

cdj

Oct 31 '06 #2

Peter Bromberg [ C# MVP ] wrote:
The DataAdapter's Update Method relies on the RowState of each row in the
datatable to tell whether to perform an update, insert, or delete. Since in
the first case you've cleared out all the DataRows, it therefore has nothing
to do.
Peter
Oooh. So is this right, in other words: the word "delete" in
DataRow.Delete *means* delete only from the DB's perspective. If I
followed up with a DataTable.rows.rowcount(), this would be unaffected
by DataRow.delete?

Whereas on the other hand, DataTable.Rows.Clear() means delete the rows
from the application's perspective. In this case,
DataTable.rows.rowcount() would be affected?

Is that kinda the idea?

Thanks for the info!

cdj

Oct 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christoph | last post by:
I'm delving into using ADO.NET for the first time. In fact, I've never done any database work using C# at all so all of this is new to me. Please bear that in mind if I am asking stupid questions....
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
2
by: Zak McGregor | last post by:
Hi all I have a table, for simplicity's sake containing one field, called unid. for example, select unid, oid from table gives me something like this: unid | oid ---------+---------
4
by: Jim Michaels | last post by:
Is it safe to do what is below? deleting from a resultset while you are processing it? I don't know how dynamic the SQL database is. I assume you get a cursor to live dataset. Even if it is a...
5
by: A | last post by:
I am wondering if there's an efficient way of deleting rows or columns of a gsl_matrix? The only way I can think of is copying individual elements or may be rows, columns or sumatrices to a new...
13
by: groupy | last post by:
input: 1.5 million records table consisting users with 4 nvchar fields:A,B,C,D the problem: there are many records with dublicates A's or duplicates B's or duplicates A+B's or duplicates B+C+D's &...
9
by: Hamed | last post by:
Hello I have a DataGrid that a is bound to a DataTable. Some of the rows in the DataTable should not be deleted. How can I prohibit deleting of some identified rows? The problem could be...
4
by: MiziaQ | last post by:
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.