Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8114971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:19:01+00:00 2026-06-06T03:19:01+00:00

I am trying to delete the data present in the dataset with following code:

  • 0

I am trying to delete the data present in the dataset with following code:

stateflowDataSet dsobject = new stateflowDataSet();
stateflowDataSetTableAdapters.dbo_statetableTableAdapter statetableadapter = new         stateflowDataSetTableAdapters.dbo_statetableTableAdapter();
statetableadapter.Fill(dsobject.dbo_statetable);
dsobject.dbo_statetable.Clear();
statetableadapter.Update(dsobject);

But after this line when use statetableadapter.Fill(dsobject.dbo_statetable); the data is still retained.

Is the way in which I am clearing the data right?

Is there any other problem with the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:19:02+00:00Added an answer on June 6, 2026 at 3:19 am

    Removing DataRows from a DataTable does not mean that you’ll delete them from your DBMS. The opposite is true, actually you’re preventing them from being deleted even if you would have called DataRow.Delete() before.

    The reason is: only DataRows that belong to a DataTable can be deleted by

    DataAdapter.Update(table)
    

    This will delete every row in the table with DataRowState=Deleted.
    Therefor you need to use the Delete method.

    foreach(DataRow row in dsobject.dbo_statetable.Rows)
    {
        row.Delete();
    }
    statetableadapter.Update(dsobject.dbo_statetable);
    

    You could do it also in one batch which would be more efficient, therefor you need to set the DataAdapter’s UpdateBatchSize to 0(unlimited).

    Another way would to delete all rows is to use a simple SqlCommand with CommandText DELETE FROM Table:

    using(var con = new SqlConnection(ConfigurationSettings.AppSettings["con"]))
    using(var cmd = new SqlCommand())
    {
        cmd.CommandText = "DELETE FROM Table";
        cmd.Connection = con;
        con.Open();
        int numberDeleted = cmd.ExecuteNonQuery();  // all rows deleted
    }
    

    Now you need to remove(not delete, what is the core of your question) the rows from the DataTable manually since you’ve also deleted them manually in the database:

    dsobject.dbo_statetable.Clear();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to delete a data from database using jquery and the following
I'm trying to delete an int[] from an ArrayList. Due to my code I
I'm trying to delete all data related to a user id from a game
I am trying to delete the data against the remove (Ajax) option.When i click
While trying to delete the data from my SQL Server CE 3.5 database, I
I am trying to delete the data from table older than 6 months where
I am trying to delete data from a table using a SQLDataAdapter , and
I'm trying to delete one row of data from a MySQL database (innodb) in
I'm trying to delete a row of data across two tables. I have the
Im new to selenium and was trying to delete some contacts which i had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.