473,549 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delete row from dataview

Sam
Hi,

As I loop through a dataview's records, I delete datarow based on a
condition. However I don't want to commit those deletions until the
loop ends. With a datatable, i would just set row.delete() and call
AcceptChanges when the loop ends. But how can I do that with a dataview
?

Thank you

Mar 2 '06 #1
16 17514
Sam,

Don't mix up the words Delete and Remove in AdoNet.

Delete marks a datarow as to be Removed by an acceptchanges or an DA.Update.
Remove removes a datarow from a DataTable.

I am not sure what you are doing, because it seems strange to me, however
you will have a solution with this.
If you do by instance this.

DataTable.Accep tChanges 'assuming that al other rowstates can be set to this
drv(0).Delete
DataTable.Accep tChanges

Than the first row that fullfils the rowfilter will be removed.

Which is than the same as
DataTable.rows. remove(drv(0).r ow)

I hope this helps,

Cor

"Sam" <sa************ *@googlemail.co m> schreef in bericht
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
Hi,

As I loop through a dataview's records, I delete datarow based on a
condition. However I don't want to commit those deletions until the
loop ends. With a datatable, i would just set row.delete() and call
AcceptChanges when the loop ends. But how can I do that with a dataview
?

Thank you

Mar 2 '06 #2
Sam
Cor,
Thanks for replying.
I'm sorry but I don't understand your example. Maybe I haven't
explained properly what I want to do.
Watch this:

For each row as datarowview in myDataView

if my condition is met then
mark row to be removed
end if

Next

commit changes here, meaning remove the rows from myDataView.

Now, I've come up with a solution, which is to convert the dataview to
a datatable using ToTable function. Then I can use .Delete and
AcceptChanges on this datatable, and then reassign the datattable to be
the source for my dataview. I know it's a bit ackward but it's the best
I could come up with. Do you have a better solution ?

Sam

Mar 2 '06 #3
Hi Sam,

If I understand your question correctly, you want to iterate through
the rows in a view, delete some of them (conditionally) , then commit
those deletes. Hopefully the code below solves your question.

Dim Row As DataRowView

For Each Row In View
If Condition = True Then
Row.Delete()
End If
Next
View.Table.Acce ptChanges()

Mar 3 '06 #4
Sam,

Sorry I forgot to answer that part, I was meaning something as Virgil wrote
however than extended with the RejectChanges if it not should be done.

http://msdn2.microsoft.com/en-us/lib...ctchanges.aspx

Be aware that you do before the AcceptChanges forever an update if that is
necessary, because your changes are by the AcceptChanges not anymore
recognisable.

I hope this helps,

Cor

"Sam" <sa************ *@googlemail.co m> schreef in bericht
news:11******** **************@ e56g2000cwe.goo glegroups.com.. .
Cor,
Thanks for replying.
I'm sorry but I don't understand your example. Maybe I haven't
explained properly what I want to do.
Watch this:

For each row as datarowview in myDataView

if my condition is met then
mark row to be removed
end if

Next

commit changes here, meaning remove the rows from myDataView.

Now, I've come up with a solution, which is to convert the dataview to
a datatable using ToTable function. Then I can use .Delete and
AcceptChanges on this datatable, and then reassign the datattable to be
the source for my dataview. I know it's a bit ackward but it's the best
I could come up with. Do you have a better solution ?

Sam

Mar 3 '06 #5
Sam
Hi,

Thank to both of you for helping me out.
Here's my code, base on what I had, mixed with Virgil's sample:

For Each row As DataRowView In dvOrig
'how many times to we have the QueryGroupId in the table
drResult = dvOrig.FindRows (row("QueryGrou pId"))
'if it appears more than once then add it to dtDest and
'delete it from dtOrig
If Not drResult.Length > 1 Then
row.Delete()
End If
Next

The issue occurs on the 3rd shot in the loop as it raises the
exception: There is no row at position 3 in the view.
This is because the row was marked as Delete, and now it tries to use
FindRows.
How can I get around this ?

Mar 3 '06 #6
Sam,

This in one of the good examples why you should do deleting in a collection
forever down to top.
(I did not look that well at the sample of Virgil)

For i as integer = mycollection.co unt-1 to 0 step -1
'the code
Next

Cor

"Sam" <sa************ *@googlemail.co m> schreef in bericht
news:11******** *************@i 40g2000cwc.goog legroups.com...
Hi,

Thank to both of you for helping me out.
Here's my code, base on what I had, mixed with Virgil's sample:

For Each row As DataRowView In dvOrig
'how many times to we have the QueryGroupId in the table
drResult = dvOrig.FindRows (row("QueryGrou pId"))
'if it appears more than once then add it to dtDest and
'delete it from dtOrig
If Not drResult.Length > 1 Then
row.Delete()
End If
Next

The issue occurs on the 3rd shot in the loop as it raises the
exception: There is no row at position 3 in the view.
This is because the row was marked as Delete, and now it tries to use
FindRows.
How can I get around this ?

Mar 3 '06 #7
Sam
Yes!!!!!!!!!!
Thank you so much Cor, it works !

Just one more question if you don't mind ! Before I delete the row, I
want to add it to another dataview. How can I do that, I can't figure
it out... Here's my code so far:

Dim drResult As DataRowView()
dvOrig.Sort = "QueryGroup Id"

For i As Integer = dvOrig.Count - 1 To 0 Step -1
drResult = dvOrig.FindRows (dvOrig(i).Item ("QueryGroupId" ))

If Not drResult.Length > 1 Then
'HERE I WANT TO ADD THE ROW TO ANOTHER DATAVIEW, WHICH
HAS THE SAME
'COLUMNS (SAME STRUCTURE) AS dvOrig.
dvOrig.Item(i). Delete()
End If
Next
dvOrig.Table.Ac ceptChanges()

Mar 3 '06 #8
Sam,

As I thought does there go something wrong,

A dataview is a view on a table. To delete it from a view, you only have to
change the part that is in the rowfilter from that.

Now you are removing the rows completely from your table. From your message
I understand now that, that is not the purpose.

So as sample

dim dv1 as new dataview(mytabl e)
dim dv2 as new dataview(mytabl e)

dv1.rowfilter = "City = 1)"
dv2.rowfilter = "City = 2)"

Now you have not to delete in your loop however something as

for i as integer = dv1.count -1 to 0
drv("City") = "2"
next

I hope this helps,

Cor


"Sa
m" <sa************ *@googlemail.co m> schreef in bericht
news:11******** *************@i 39g2000cwa.goog legroups.com...
Yes!!!!!!!!!!
Thank you so much Cor, it works !

Just one more question if you don't mind ! Before I delete the row, I
want to add it to another dataview. How can I do that, I can't figure
it out... Here's my code so far:

Dim drResult As DataRowView()
dvOrig.Sort = "QueryGroup Id"

For i As Integer = dvOrig.Count - 1 To 0 Step -1
drResult = dvOrig.FindRows (dvOrig(i).Item ("QueryGroupId" ))

If Not drResult.Length > 1 Then
'HERE I WANT TO ADD THE ROW TO ANOTHER DATAVIEW, WHICH
HAS THE SAME
'COLUMNS (SAME STRUCTURE) AS dvOrig.
dvOrig.Item(i). Delete()
End If
Next
dvOrig.Table.Ac ceptChanges()

Mar 3 '06 #9
Sam
This is not that simple. Here's what I'm trying to achieve.

I have two dataviews with same structure. They both have a field named
'QueryGroupId'. In dvDest, all the records have QueryGroupId = NULL. In
dvOrig, there are records which have the same QueryGroupId.

I'm trying to delete records from dvOrig where the QueryGroupId is
unique, that is, it does not appear more than once. But before I delete
this record, I want to move it to dvDest.

Therefore I can't use rowfilter, unless you know a way to get the
records that were rejected by the filter ?
Does it make it clearer ?

Mar 3 '06 #10

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

Similar topics

3
2587
by: Michael Schindler | last post by:
Hello NG How I can delete a specific cell in my Datagrid. I would like if the user is in the column 6 the value changed, after automaticly the value in the column 7 in the same row to delete. Thanks
1
1801
by: J | last post by:
Hi, Can someone please help with a problem I have. The BOL I think are useless in explaining what I want to do. I have a datagrid, that is bound to a dataview. I have a checkbox as a template column and a button marked 'delete'. What I want to do, is be able to select a series of rows from the datagrid, using the checkboxes, and...
1
1299
by: Kashif Mehmood | last post by:
Greeting I am using the following code to delete a row from a datagrid ---------------- Private Sub dgClientTypes_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgClientTypes.DeleteComman cmdClientTypes.CommandText = "Delete from tbClientTypes where (ClientTypeID =...
1
1501
by: alan | last post by:
in my project there are 5 textbox : tbOrderid, tbSeqNum, tbFoodCode, tbFoodDesc and tbPrice 9 button: btInsert, btdelete, btUpdate, btClear, btBind, btFirst, btPrevious, btNext and btLast i cannot do the insert and delete function. Can anybody help me? If you need the program I can email to anyone who want to help me, thanks!! ^^Alan ...
3
1701
by: s.lustre | last post by:
after adding controls to a panel on my form, i need to delete them. does anybody know how to programatically delete controls? 'my add function works For i = 0 To DirectCast(dgRoutingTable.DataSource, DataView).Count() Dim u As New RoutingControl.RoutingControl With u ..Comments = i.ToString ..Location = New System.Drawing.Point(0, 136 *...
4
22384
by: Henry J. | last post by:
Can somebody tell me how to delete multiple rows in a datagridview selected by the user? I tried the following two methods to no avail. I have a myDataGridView that is bound to myDataTable's myDataView. The column "Name" is the primary key. I want to delete the rows selected by the user: foreach (DataGridViewRow drv in...
0
1133
by: teo | last post by:
I previously put a Dataview in the Cache Me.Cache.Insert("myDVname", DV) Now I retrieve it Dim DV As DataView = Me.Cache("myDVname") and populated a ListBox All is ok.
3
8476
by: Nitinkcv | last post by:
Hi, While trying to run my app im getting the error Could not find a part of the path "c:\inetpub\wwwroot\Do not Delete\dbglobal.config". I checked and found that there is no Important_Do not Delete folder inside the wwwroot. The error occurs when i try to use the following code: //inside my test.aspx
3
2270
by: MarkusJNZ | last post by:
Hi, I have a dataview which I am using to bind to a gridview. In the page load event I am checking for a condition in each row of the dataview and if it exists I want to remove the row from the dataview before I bind it to the gridview; Pseudo code below ================ DataView people = ExecuteDataSet.Tables.DefaultView;
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5369
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.