delete db row via tableadapter?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AW

    delete db row via tableadapter?

    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]

    #2
    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

    Comment

    • Jack Jackson

      #3
      Re: delete db row via tableadapter?

      On Sat, 09 Feb 2008 22:03:58 -0800, AW <wrote:
      >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.Upd ate() before calling
      datatable.Accep tChanges().

      dataadapter.Upd ate() is what updates the database with the rows that
      are modified in the datatable. Datatable.Accep tChanges() 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.

      Comment

      • AW

        #4
        Re: delete db row via tableadapter?

        On Sun, 10 Feb 2008 07:34:15 +0100, "Cor Ligthert[MVP]"
        <notmyfirstname @planet.nlwrote :
        >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
        >DBDataAdapte r (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.De leteQuery(str)
        And then ran the program again - deleted stuff gone.
        Amazingly simple but try finding it in "help".

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: delete db row via tableadapter?

          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.De leteQuery(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.



          Cor

          Comment

          Working...