Я использую приведенный ниже код для импорта данных из файла Excel в виде таблицы. Но я получаю ошибку.
protected void uploadLinkButton_Click(object sender, EventArgs e)
{
string name = "Items";
string path = Server.MapPath(StyleOperationsFileUpload.FileName);
string Constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=2;'";
OleDbConnection OleCon = new OleDbConnection(Constr);
OleDbCommand OleCom = new OleDbCommand("Select * From [" + name + "$]", OleCon);
OleCon.Open();
OleDbDataAdapter OleAdapObj = new OleDbDataAdapter(OleCom);
DataTable DatTabObj = new DataTable();
OleAdap.Fill(DatTab);
UploadGridView.DataSource = DatTab;
UploadGridView.DataBind();
}
Ошибка, как показано ниже
ядру базы данных Microsoft Access не удалось найти объект
'Элементы $'. Убедитесь, что объект существует, и что вы пишете его имя и
имя пути правильно. Если «Items $» не является локальным объектом, проверьте
подключение к сети или обратитесь к администратору сервера.
Полная трассировка стека и ошибка, как показано ниже
System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147217865
HResult=-2147217865
Message=The Microsoft Access database engine could not find the object 'Items$'. Make sure the object exists and that you spell its name and the path name correctly. If 'Items$' is not a local object, check your network connection or contact the server administrator.
Source=Microsoft Access Database Engine
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at StyleOperations.Operations.uploadLinkButton_Click(Object sender, EventArgs e) in D:\Developments\On Going Developments\StyleOperations\StyleOperations\StyleOperations\Operations.aspx.cs:line 145
at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Пожалуйста, помогите мне решить эту проблему. Заранее спасибо.
Ниже приведен формат файла Excel. Имя файла Excel: Лист1
| 1 |DESCRIPTION| SMV |SEQ NO
| 2 | Des1 | 1.2 | 1
| 3 | Des2 | 2.5 | 2
| 4 | Des3 | 5.8 | 3
| 5 | Des4 | 4.2 | 4