Using Dataset.Clear() to clear an SQL-database

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

    Using Dataset.Clear() to clear an SQL-database

    Is it possible to use

    dataset.Clear() ;
    dataAdapterSome thing.Update(da taset.table);

    to clear a table in an SQL database?

    I am not able to get this to work. The dataset clears, but the changes
    are not updated into the database.

  • Marina Levit [MVP]

    #2
    Re: Using Dataset.Clear() to clear an SQL-database

    You would have to mark each row for deletion. Clearing the dataset
    physically removes all the rows.

    "Cub71" <bjornbj@gmail. comwrote in message
    news:1163602169 .679179.178160@ h54g2000cwb.goo glegroups.com.. .
    Is it possible to use
    >
    dataset.Clear() ;
    dataAdapterSome thing.Update(da taset.table);
    >
    to clear a table in an SQL database?
    >
    I am not able to get this to work. The dataset clears, but the changes
    are not updated into the database.
    >

    Comment

    • Ciaran O''Donnell

      #3
      RE: Using Dataset.Clear() to clear an SQL-database

      Just use a SqlCommand to run either
      Delete From TableName
      if the table is referenced by foreign key constraints.
      If it isnt:
      Truncate Table TableName

      Truncate also resets Identity columns whereas delete doesnt.

      Ciaran O'Donnell

      "Cub71" wrote:
      Is it possible to use
      >
      dataset.Clear() ;
      dataAdapterSome thing.Update(da taset.table);
      >
      to clear a table in an SQL database?
      >
      I am not able to get this to work. The dataset clears, but the changes
      are not updated into the database.
      >
      >

      Comment

      • Cub71

        #4
        Re: Using Dataset.Clear() to clear an SQL-database


        Ciaran O''Donnell skrev:
        Just use a SqlCommand to run either
        Delete From TableName

        Thank you. That is what I ended up doing.

        Comment

        Working...