delete db row via tableadapter?

  • Thread starter Thread starter AW
  • Start date Start date
A

AW

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.
 
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
 
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,

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".
 
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".

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
 
Back
Top