473,396 Members | 1,971 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,396 software developers and data experts.

Problem deleting rows from dataset (VS2003, VB)

Hello,

I have a datagrid (grdShots) on a form, and a button to allow the user
to delete records from the dataset underlying the grid. My code
appears to work, because the row disappears from the datagrid. But the
delete is not being updated back to the data source, because if I exit
the app then start it again, the record reappears in the grid - it has
not been deleted. Code for deleting the row is as follows. Column 0
in the grid is the ID of the record, which is its primary key.

Dim iImage as Long
Dim dr as DataRow

iImage = grdShots.Item(grdShots.CurrentRowIndex, 0)
If MsgBox("Are you sure you want to delete this?",
MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
dr = dsShots.Tables("Shot").Rows.Find(iImage)
dsShots.Tables("Shot").Rows.Remove(dr)
daShots.Update(dsShots)
End If

What more do I need to do?

Mar 27 '06 #1
3 1725
Marshall,

Replace the remove by a "delete" equivalent.

The remove, removes a datarow from a datatable/dataset
The delete marks a row as to be removed by the next update or by an
acceptchanges.

I hope this helps,

Cor

"marshallarts" <st****@westnet.net.au> schreef in bericht
news:11**********************@j33g2000cwa.googlegr oups.com...
Hello,

I have a datagrid (grdShots) on a form, and a button to allow the user
to delete records from the dataset underlying the grid. My code
appears to work, because the row disappears from the datagrid. But the
delete is not being updated back to the data source, because if I exit
the app then start it again, the record reappears in the grid - it has
not been deleted. Code for deleting the row is as follows. Column 0
in the grid is the ID of the record, which is its primary key.

Dim iImage as Long
Dim dr as DataRow

iImage = grdShots.Item(grdShots.CurrentRowIndex, 0)
If MsgBox("Are you sure you want to delete this?",
MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
dr = dsShots.Tables("Shot").Rows.Find(iImage)
dsShots.Tables("Shot").Rows.Remove(dr)
daShots.Update(dsShots)
End If

What more do I need to do?

Mar 27 '06 #2
Unbelievable! Thank you, that worked. When would anyone use the
Remove method, for heaven's sake?? I can't get my head around what its
purpose is.

Mar 27 '06 #3

"Steve Marshall" <st****@westnet.net.au> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
Unbelievable! Thank you, that worked. When would anyone use the
Remove method, for heaven's sake?? I can't get my head around what its
purpose is.


Possibly after a Remove that row will not be altered on the DB after a
resynch?

Mar 27 '06 #4

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

Similar topics

1
by: Junkguy | last post by:
I'm having difficulty deleting rows from a datagrid. I want to put a "delete" button on a form and achieve the same functionality as hitting the "delete" key on the keyboard for the selected row of...
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...
3
by: Abra | last post by:
My C# application has a list (ListBox object), connected over a DataView to a dataset which corresponds to a table from a MySql database. I want to delete for example 4000-5000 rows from the table,...
5
by: Robert Brown | last post by:
Hi All. I have a routine that checks a SQL Table for all records 3 months prior to a predetermined date, then I insert them into an Archive DB then delete those records from the original table....
3
by: Bob Day | last post by:
I need to delete ALL rows in a dataset and currently use the method in the code snippet below, which works fine. However, there can be 100,000 rows, which makes the FILL, DR.Delete and UPDATE take...
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...
7
by: Bob | last post by:
Hi, I have a typed unbound dataset that is passed to a datahandling class to be filled. The datahandling class fills it from a sproc using an oledbDataAdapter (SQLAnywhere database) The only...
2
by: sherifffruitfly | last post by:
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.Rows.Clear(); dataadapter.Update(dataset,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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
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...

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.