c#: fail to add column to sheet

0

I try to add a new column to a sheet using the following code:

try
{
    string connection_string = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
                               @"Data Source=" + file_path + ";" +
                               @"Extended Properties='Excel 12.0 XML;'";

    OleDbConnection ole_db_connection = new OleDbConnection(connection_string);
    ole_db_connection.Open();

    OleDbCommand cmd = new OleDbCommand("ALTER TABLE [" + sheet_name + "] ADD COLUMN " + column_name + " DOUBLE",
                                        ole_db_connection);
    cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
    MessageBox.Show("cannot perform database operation, " + ex.ToString(), "EXCEPTION");
}

The error I get is "System.Data.OleDb.OleDbException (0x80004005)".

c#
oledb
oledbconnection
oledbcommand
asked on Stack Overflow Sep 26, 2018 by user180574

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0