4
I have the following piece of code that connects to excel, where it will delete the data from a tab of a spreadsheet.
private void AtualizarPerformanceEntrega()
{
try
{
string sFileXLSX = Server.MapPath("ExportPerformanceEntrega");
string strConnXLSX = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + sFileXLSX + "';Extended Properties=Excel 12.0;";
using (OleDbConnection connection = new OleDbConnection(strConnXLSX))
{
//SQL para fazer o INSERT
string strSQL = "DELETE FROM [Base Entregue$]";
//Criando o OleDbCommand com o SQL e a conexão
OleDbCommand cmd = new OleDbCommand(strSQL, connection);
//Abrindo a conexão
connection.Open();
//Executando o INSERT
cmd.ExecuteNonQuery();
//Fechando a conexão
connection.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}
But the following error returns to me:
"The Microsoft Office Access database engine could not find the Object 'Base Entregue1$'. Make sure the Object exists and that you Spell its name and the path name correctly."
Parameter of the web.config
<add key ="ExportPerformanceEntrega" value="C:\Entrega\Performance.xlsx"/>
Tab name I want to make the exclusion:
Obs.¹ This spreadsheet is blocked and always when it opens it has to enable editing
Obs.² Maybe it is the name of the tab, because it is separate?
Strange, in your query you pass "[Base Entregue1$]", but the name of the spreadsheet you highlighted is without this "1". Is that correct? I don’t have excel installed to test here.
– L. Albano
@L.Albano then even correcting the code to leave the name equal, still returns the same error
– Igor Carreiro
Shouldn’t the address be with 2 bars? value=" C: Delivery Performance.xlsx"
– Alexandre Cavaloti