I have a big excel document, so I decided to use an OleDbconneciton to open and edit it. It is not problem when I open it. I just use Select command just like SQL, but when I try to change data from some column, I get an error -> Data type mismatch in criteria expression. That is a sample of update string generator:
this._updateCommand = string.Format("UPDATE [{0}${1}{2}:{1}{2}] SET F{3} = ?", workSheet, ((DATA_COL)this._cellIndex).ToString(), this._rowIndex, "1");
On export it gets:
"UDPATE [worksheet$B1:B1] SET F1 = ?"
Nextstep:
Task task = Task.Run(() => {String connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; Mode=ReadWrite; Data Source={0}; Extended Properties='Excel 8.0; HDR=NO; IMEX=3;'", this.WorkBook);
for (int i = 0; i < this.editCollection.Count; i++)
{
OleDbConnection connection = new OleDbConnection(connectionString);
try
{
OleDbCommand command = new OleDbCommand(editCollection[i]._updateCommand, connection);
command.Parameters.AddWithValue("@thisData", editCollection[i]._value);
command.CommandType = CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
connection.Dispose();
}
}
editCollection.Clear();
});
So, what I did wrong?