Connecting Tech Pros Worldwide Forums | Help | Site Map

delete db row via tableadapter?

AW
Guest
 
Posts: n/a
#1: Feb 10 '08
XP & VB 2005 using the help files - followed instructions to use the
table adapter to delete a row from the database.
I step thru the table find the rows to delete and
issue a .Delete() and
after having done that for all the rows I want to delete
issue an AcceptChanges().
I get NO errors but the database is unchanged.
Google has several suggestions that seem very complex.
VB 2005 is supposed to be simple and direct - Not?
Help? Suggestions? Point to help? Thanks.
Cor Ligthert[MVP]
Guest
 
Posts: n/a
#2: Feb 10 '08

re: delete db row via tableadapter?


AW,

A database has nothing to do with an AcceptChanges, what an accept changes
does is setting all the rows to unchanged and removing all rows that have
the rowstate deleted. All first state information is removed from the Row.

Deleting a row in a database goes in fact with a SQL statement.

If you use a datatable however, then the delete is done by the DataAdapter
in the Update of the TableAdapter (which I never have used) or the
DBDataAdapter (which I always use).

Therefore, show some code.

Cor

Jack Jackson
Guest
 
Posts: n/a
#3: Feb 10 '08

re: delete db row via tableadapter?


On Sat, 09 Feb 2008 22:03:58 -0800, AW <wrote:
Quote:
>XP & VB 2005 using the help files - followed instructions to use the
>table adapter to delete a row from the database.
>I step thru the table find the rows to delete and
>issue a .Delete() and
>after having done that for all the rows I want to delete
>issue an AcceptChanges().
>I get NO errors but the database is unchanged.
>Google has several suggestions that seem very complex.
>VB 2005 is supposed to be simple and direct - Not?
>Help? Suggestions? Point to help? Thanks.
You need to call dataadapter.Update() before calling
datatable.AcceptChanges().

dataadapter.Update() is what updates the database with the rows that
are modified in the datatable. Datatable.AcceptChanges() then marks
all of the rows in the datatable as being not modified.

Don't forget to build the dataadapter DeleteCommand, InsertCommand and
UpdateCommand properties with the appropriate SQL statements.
AW
Guest
 
Posts: n/a
#4: Feb 11 '08

re: delete db row via tableadapter?


On Sun, 10 Feb 2008 07:34:15 +0100, "Cor Ligthert[MVP]"
<notmyfirstname@planet.nlwrote:
Quote:
>AW,
>
>A database has nothing to do with an AcceptChanges, what an accept changes
>does is setting all the rows to unchanged and removing all rows that have
>the rowstate deleted. All first state information is removed from the Row.
>
>Deleting a row in a database goes in fact with a SQL statement.
>
>If you use a datatable however, then the delete is done by the DataAdapter
>in the Update of the TableAdapter (which I never have used) or the
>DBDataAdapter (which I always use).
>
>Therefore, show some code.
>
>Cor
OK, I followed some of your advice - I created a DeleteQuery in the
TableAdapter. Then I looped thru the rows of the DataGridView and when
I found a row to delete, I called the Sql DeleteQuery with Where
(ColSym=string) - TableAdapter.DeleteQuery(str)
And then ran the program again - deleted stuff gone.
Amazingly simple but try finding it in "help".
Cor Ligthert[MVP]
Guest
 
Posts: n/a
#5: Feb 12 '08

re: delete db row via tableadapter?


OK, I followed some of your advice - I created a DeleteQuery in the
Quote:
TableAdapter. Then I looped thru the rows of the DataGridView and when
I found a row to delete, I called the Sql DeleteQuery with Where
(ColSym=string) - TableAdapter.DeleteQuery(str)
And then ran the program again - deleted stuff gone.
Amazingly simple but try finding it in "help".
You should never try to access the grid directly, one of the reasons is,
that because that it can be sorted, the showed rows can be not in line with
the real rows.

Try to use forever what is in the BindingSoure. (The datasource).

I never use the tableadapters, however a text from Ken.

http://www.vb-tips.com/ExtendTableAdapter.aspx

Cor

Closed Thread