473,545 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting a Row from the Data Source with Table Adapter

Hi,
Trying to pass along a table row delete to the datasource, but I'm
crashing. Here is the code:

Private Sub btnDeleteIngr_C lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnDeleteIngr.C lick
Dim vbResponse As Integer
vbResponse = MessageBox.Show ("Are you sure that you want to
delete " + tbIngr.Text + "?", "Confirm Delete",
MessageBoxButto ns.OKCancel, MessageBoxIcon. Warning)
If vbResponse = 1 Then
Dim dr As DataRow
Dim drv As DataRowView
drv = bsIngredients.C urrent
dr = drv.Row
dr.Delete()
bsIngredients.M oveNext()
taIngredients.U pdate(dsMenuPla nner.Ingredient s)
dsMenuPlanner.A cceptChanges()
End If
End Sub

It's the "taIngredients. Update(dsMenuPl anner.Ingredien ts)" line that
crashes. The error is "Update requires a valid DeleteCommand when
passed DataRow collection with deleted rows."

I can't figure out how to resolve this. Can anybody help?

Thanks,
Randy

Apr 22 '07 #1
12 19953
Your data adapter must have InsertCommand, DeleteCommand, and UpdateCommand
objects defined for it in order to perform updates.

Robin S.
--------------------------------
"Randy" <sp***********@ gmail.comwrote in message
news:11******** **************@ p77g2000hsh.goo glegroups.com.. .
Hi,
Trying to pass along a table row delete to the datasource, but I'm
crashing. Here is the code:

Private Sub btnDeleteIngr_C lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnDeleteIngr.C lick
Dim vbResponse As Integer
vbResponse = MessageBox.Show ("Are you sure that you want to
delete " + tbIngr.Text + "?", "Confirm Delete",
MessageBoxButto ns.OKCancel, MessageBoxIcon. Warning)
If vbResponse = 1 Then
Dim dr As DataRow
Dim drv As DataRowView
drv = bsIngredients.C urrent
dr = drv.Row
dr.Delete()
bsIngredients.M oveNext()
taIngredients.U pdate(dsMenuPla nner.Ingredient s)
dsMenuPlanner.A cceptChanges()
End If
End Sub

It's the "taIngredients. Update(dsMenuPl anner.Ingredien ts)" line that
crashes. The error is "Update requires a valid DeleteCommand when
passed DataRow collection with deleted rows."

I can't figure out how to resolve this. Can anybody help?

Thanks,
Randy

Apr 22 '07 #2
Randy,

I have somehow the idea that your update should be
taIngredients.U pdate(dsMenuPla nner.bsIngredie nts)

If it is not that, and it is as Robin suggest, add than before that row
cmb = oledbCommandbui lder(taIngredie nts)
or
SQLCommandBuild er(taIngredient s)

'depending on what you use
http://msdn2.microsoft.com/en-us/lib...ndbuilder.aspx

I hope this helps,

Cor
"Randy" <sp***********@ gmail.comschree f in bericht
news:11******** **************@ p77g2000hsh.goo glegroups.com.. .
Hi,
Trying to pass along a table row delete to the datasource, but I'm
crashing. Here is the code:

Private Sub btnDeleteIngr_C lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnDeleteIngr.C lick
Dim vbResponse As Integer
vbResponse = MessageBox.Show ("Are you sure that you want to
delete " + tbIngr.Text + "?", "Confirm Delete",
MessageBoxButto ns.OKCancel, MessageBoxIcon. Warning)
If vbResponse = 1 Then
Dim dr As DataRow
Dim drv As DataRowView
drv = bsIngredients.C urrent
dr = drv.Row
dr.Delete()
bsIngredients.M oveNext()
taIngredients.U pdate(dsMenuPla nner.Ingredient s)
dsMenuPlanner.A cceptChanges()
End If
End Sub

It's the "taIngredients. Update(dsMenuPl anner.Ingredien ts)" line that
crashes. The error is "Update requires a valid DeleteCommand when
passed DataRow collection with deleted rows."

I can't figure out how to resolve this. Can anybody help?

Thanks,
Randy

Apr 22 '07 #3
Thank you both for your advice. I thought that I had a DeleteCommand
set up, but I did it wrong. I did it in the table adapter on the
designer rather than in the properties. That's now fixed and the code
executes without error.

I still have one problem. I haven't set up the CommandText
correctly. What I have in there is "DELETE FROM Ingredients", which
obviously deletes all records from the table Ingredients. Can you
help me to change this query to just delete the table that the user
has selected? It's always going to be the current row. The code
above has not changed. Let me know if I can provide more information.

Thanks again!
Randy
Apr 22 '07 #4
Can you help me to change this query to just delete the table that the user
has selected?
Sorry, I meant the row that the user has selected (not the table).

Apr 22 '07 #5
Randy,

That depends how the user has selected it, I know at least 10 simple ways.

Cor

"Randy" <sp***********@ gmail.comschree f in bericht
news:11******** *************@o 5g2000hsb.googl egroups.com...
>Can you help me to change this query to just delete the table that the
user
has selected?

Sorry, I meant the row that the user has selected (not the table).

Apr 23 '07 #6
Using the binding navigator, the user scrolls through the records in
the table. If they see one that they don't want any longer, they
click a button intended to delete the current row from the data
table. Very straightforward from a user perspective, and I think is
pretty simple programatically . I just don't know enough to write the
SQL command so that it just deletes the current row and not all of the
records.

Thanks for any advice.
Randy

Apr 23 '07 #7
Randy,

If it is a row in a table, than the row will be marked as deleted. (it will
not deleted, if you want that, than you have to remove it, but than it will
not be deleted from yourdatabase).

It will not be showed anymore, however it is still there, the same is for an
updated and a new record, they are marked as updated and new. It is clever
done, if you delete a row and afterwards insert in your idea a new one, the
rowstate is set to "update".

When you now give your datatable to the database using the dataadapter or
tableadapter, than select those the rowstate which are changed, those will
be processed in the database and automatically is done by the adapter, the
acceptchanges which is to set the rowstates to all changes done.

This is one of the methods to do your updates, I hope it gives an idea,

Cor


"Randy" <sp***********@ gmail.comschree f in bericht
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
Using the binding navigator, the user scrolls through the records in
the table. If they see one that they don't want any longer, they
click a button intended to delete the current row from the data
table. Very straightforward from a user perspective, and I think is
pretty simple programatically . I just don't know enough to write the
SQL command so that it just deletes the current row and not all of the
records.

Thanks for any advice.
Randy

Apr 23 '07 #8
As Cor said, if he deletes one, it is marked as a delete and no longer
displayed. Usually you call your tableadapter or dataadapter after the user
has completed all changes. The adapter checks the state of each row. If it
was Added, it executes the Insert command; if it was Modified, it executes
the Update command; if it was Delete, it executes the Delete command. The
delete command should be something like "DELETE FROM myTable WHERE
myPrimaryKey = @myPrimaryKey", and you pass in the parameter.

I don't use table adapters; they're not precise enough for me. I write my
own stored procs and execute my own code against them. Are you actually
using a strongly typed dataset and table adapter, or are you using a data
adapter and regular dataset?

Robin S.
--------------------------
"Randy" <sp***********@ gmail.comwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
Using the binding navigator, the user scrolls through the records in
the table. If they see one that they don't want any longer, they
click a button intended to delete the current row from the data
table. Very straightforward from a user perspective, and I think is
pretty simple programatically . I just don't know enough to write the
SQL command so that it just deletes the current row and not all of the
records.

Thanks for any advice.
Randy

Apr 24 '07 #9
I was using a table adapter, but I've since switched to data
adapters. I'm finding more resources explaining data adapters, so I'm
heading in that direction. I think that for the simple types of
actions that I am doing, either would probably work fine.

Thanks again for all of your help.

Randy

Apr 26 '07 #10

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

Similar topics

1
4532
by: VMI | last post by:
How can I dump a datatable into an Access table (which contais exactly the same structure)? Somebody suggested doing this with a dataAdapter. I don't want to run an Insert query for each record (I assume that if the datatable and the Access table have the same structure, I can just dump it from one place to the other). I'd be dumping data to...
12
7545
by: VMI | last post by:
For some reason, the process of retrieving data (about 20 records) from an Access table that has 400K records to a dataTable is taking over 3 mins. to complete. Below is my code to connect to the DB and query the table. The table "audit" primary key is "Line". Another weird thing (but I guess that's another post) is that, while it's doing...
9
2052
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1. Assign to a datarow (dr1) the first record of the MASTER table 2. Assign to another datarow (dr2) the second record of the MASTER table 3. If...
9
2813
by: Jenden0 | last post by:
I'm new to C# (and Microsoft in general) so this may be a simple problem, but I haven't been able to figure it out yet. I've got a database with a number of different tables and I want the user to be able to select which table they want, then have that table pop up in a datagridview. I've figured out how to get it to work if I specify the...
7
6591
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer include them in the set that is displayed to the user) but I don't want to delete the corresponding row from the database. I've tried using the...
6
8144
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru...
0
3953
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db.Name) conn.Open() Dim oda As New OleDb.OleDbDataAdapter("select " & sqlCols & "...
2
1522
by: ashish1985s | last post by:
using System.IO; using System.Data; using System.Collections; using System.Configuration; using System.Xml; using System.Data.SqlClient; using System; using log4net; using log4net.Config;
6
2931
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1) Constraint pk_table1 Primary Key,
0
7468
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
7656
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
7757
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...
1
5329
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
4945
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...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.