Unfortunately when I run the code I get an error message about not providing a key as an argument to the get update method.
The reason of this error is explained in this article that you should read carrefully: How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET
You are using one of the solution mentionned in this article to update the worksheet, ie Make changes to a DataSet that you have filled with a table/query from an Excel workbook and then call the Update method of the DataAdapter to resolve changes from the DataSet back to the workbook.
But just after we can read:
However, to use the Update method for change resolution you must set parameterized commands for the DataAdapter's InsertCommand
INSERT INTO [Sheet1$] (F1, F2) values (?, ?)
and UpdateCommand:
UPDATE [Sheet1$]SET F2 = ? WHERE F1 = ?
Parameterized INSERT and UPDATE commands are required because the OleDbDataAdapter does not supply key/index information for Excel workbooks; without key/index fields, the CommandBuilder cannot automatically generate the commands for you.
The message is clear: you have to explicitly write parameterized INSERT
and UPDATE
commands if you want achieve what you are trying to do.
And don't forget that Excel has a lot a functionnality but is not especially designed to work as a database. So to avoid a lot of problems, I recommand you to switch to another local database (SqlServerCompact, SQlLite, ...).