mercredi 1 avril 2015

OleDb Insert into Excel file skips "empty" rows

I am strugegling with OleDb insert command into Excel file. It skips rows that were deleted in past.


In my C# code I have following insert call via OledDb command.



cmd.CommandText = "INSERT INTO [input$] ([RowName], [RowValue]) VALUES ('blah', 'super blah')";
cmd.ExecuteNonQuery();


after this insert table looks like this:



RowName | RowValue
blah | super blah
|


so far so good. Problems occurs when user deletes values from this table (press Delete key). When I call another insert into the same table I expected values to be inserted into first empty row (in this case it should be row 1), but it actually inserts values into second row.


Insert command:



cmd.CommandText = "INSERT INTO [input$] ([RowName], [RowValue]) VALUES ('blah2', 'weak blah')";
cmd.ExecuteNonQuery();

// Expected result:
RowName | RowValue
blah2 | weak blah
|

// Actual result
RowName | RowValue
|
blah2 | weak blah


Is there any way (without using ID row and use updates instead of inserts) how to fix this error?


Aucun commentaire:

Enregistrer un commentaire