Исключение типа "System.InvalidOperationException" произошло в System.Data.dll, но не было обработано

Когда я пытаюсь загрузить файл, я получаю это исключение:

Исключение типа "System.InvalidOperationException" произошло в System.Data.dll, но не было обработано в коде пользователя.

Дополнительная информация: поставщик "Microsoft.ACE.OLEDB.12.0" не зарегистрирован на локальном компьютере.

В чем причина ошибки?

[HttpPost]
public ActionResult UploadExcel(Music objEmpDetail, HttpPostedFileBase FileUpload)
{
    Database1Entities4 objEntity = new Database1Entities4();
    string data = "";
    if (FileUpload != null)
    {
        if (FileUpload.ContentType == "application/vnd.ms-excel" || 
            FileUpload.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
        {
            string filename = FileUpload.FileName;

            if (filename.EndsWith(".xlsx"))
            {
                string targetpath = Server.MapPath("~/DetailFormatInExcel/");
                FileUpload.SaveAs(targetpath + filename);
                string pathToExcelFile = targetpath + filename;

                string sheetName = "Sheet1";

                var excelFile = new ExcelQueryFactory(pathToExcelFile);
                var empDetails = from a in excelFile.Worksheet<Music>(sheetName) select a;
                foreach (var a in empDetails)
                {
                    int result = PostExcelData(a.Name, a.Artist, a.Year, a.DateAdded, a.Style, a.Language);
                    if (result <= 0)
                    {
                        data = "Hello User, Found some duplicate values! Only unique employee number has inserted and duplicate values(s) are not inserted";
                        ViewBag.Message = data;
                        continue;
                    }
                    else
                    {
                        data = "Successful upload records";
                        ViewBag.Message = data;
                    }
                }
            }
            else
            {
                data = "This file is not valid format";
                ViewBag.Message = data;
            }
            return View("ExcelUpload");
        }
        else
        {
            data = "Only Excel file format is allowed";

            ViewBag.Message = data;
            return View("ExcelUpload");
        }
    }
    else
    {
        if (FileUpload == null)
        {
            data = "Please choose Excel file";
        }
        ViewBag.Message = data;
        return View("ExcelUpload");
    }
}

public int PostExcelData(string name, string artist, string year, string dataAdded, string style, string language)
{
    Database1Entities4 DbEntity = new Database1Entities4();
    Music music = new Music();
    music.Name = name;
    music.Artist = artist;
    music.Year = year;
    music.DateAdded = dataAdded;
    music.Style = style;
    music.Language = language;
    var InsertExcelData = DbEntity.Musics.Add(music);

    return 1;
}

Вот скриншот прилагается:

0 ответов

Другие вопросы по тегам