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 7997975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:06:20+00:00 2026-06-04T15:06:20+00:00

I have just started to learn C# and I’m a little bit confused about

  • 0

I have just started to learn C# and I’m a little bit confused about DataSet/DataTable/DataGridView.
For now I’m having a simple form where there is DataGridView, listBox, Insert & Delete buttons. When my form loads in listBox I’m getting excel sheet’s list. Then I choose one of the sheets and then it appears on DataGridView (all information I’m writing to DataSet and DataTable). I would like to add or delete columns at runtime. Here is my code for Delete button:

    excelConn = new OleDbConnection();
    excelConn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + excelFilePath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
    DataTable dt = new DataTable();
    OleDbDataAdapter ExcelAdapt = new OleDbDataAdapter("Select * From " + "[" + tableName + "]", excelConn);
    ExcelAdapt.Fill(dt);
    try
    {
      dt.Columns.Remove(colName);
      dt.AcceptChanges();
      var bds = new BindingSource();
      bds.DataSource = dt;
      grid.DataSource = bds;

      MessageBox.Show("Column(s) deleted ");
      excelConn.Close();
      }

      catch (Exception ex)
      {
         MessageBox.Show(ex.Message);
      }

The problem I’m facing is that I can’t save changes made at runtime and even at runtime these changes are temporary. If at runtime I add new column and then I choose another sheet from ListBox these changes disappear.

I found this tutorial but if I understood well it changes database; well in my case it would change excel file (but I want to have original excel file and making changes only in DataSet and DataTable).

Can I make changes only in DataSet/DataTable. If yes, then how?

  • 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-04T15:06:21+00:00Added an answer on June 4, 2026 at 3:06 pm

    Here is the exact solution for your problem which does update the data from DataGridView to Excel, I just tested on my machine and it did worked:

    http://blogs.msdn.com/b/spike/archive/2008/10/29/how-to-update-an-excel-worksheet-using-dataset-and-the-oledbdataadapter.aspx

    [Edit]

    For example the following code will remove Row #3 from the DataGridView1 and local copy of your ds however your EXCEL will not be affected.

    dataGridView1.Rows.RemoveAt(2);
    ds.Tables["[Sheet1$]"].Rows[2].Delete();
    

    Later when you want to save this data to other EXCEL, you can just export to new EXCEL or same EXCEL different [SheetX].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started to learn swing by myself, I'm little bit confused why my
I have just started to learn about the pros of foreign keys in database
I've just started to learn about tie . I have a class named Link
I have just started trying to learn Git and I have got a little
I have just started to learn about Java. I have figured out how to
I just started to learn Ruby on Rails. Now I created a simple project
I have just started to learn how to code iOS apps. I have made
I have just started learning Rails, is it required for me to learn CoffeeScript
I have just started using RSpec and I copied the very simple test on
I have just started to learn the very basics of Java programming. Using a

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.