简体   繁体   English

使用ASP.NET MVC中的验证将记录从Excel工作表导入SQL Server

[英]Import records from Excel sheet into SQL Server with validations in ASP.NET MVC

I'm just following this tutorial to import records from an Excel sheet into SQL Server with validations. 我只是按照本教程将带有验证的数据从Excel工作表导入到SQL Server中。

It's done using Webforms, here I'm trying to do it using asp.net mvc 5 它是使用Webforms完成的,在这里我尝试使用asp.net mvc 5

This is the controller class 这是控制器类

This is the Viewpage file 这是Viewpage文件

But here I'm getting following errors 但是在这里我得到以下错误

The name 'uploaddata' does not exist in the current context 名称“ uploaddata”在当前上下文中不存在

Getting this error in ImporttoDatatable() method ImporttoDatatable()方法中获取此错误

The name 'gvEmployee' does not exist in the current context 名称“ gvEmployee”在当前上下文中不存在

Getting this error in BindGrid() method BindGrid()方法中获取此错误

'Page' is a type, which is not valid in the given context “页面”是一种类型,在给定的上下文中无效

Getting this error in CheckData() method CheckData()方法中获取此错误

So if you are using MVC5 you should be using Data Annotations on a view model/model for validation. 因此,如果您使用的是MVC5,则应该在视图模型上使用数据注释进行验证。 Instead of creating all the methods to do it for you, see here https://msdn.microsoft.com/en-us/library/dd901590(VS.95).aspx . 而不是创建所有方法来帮助您完成操作,请参见此处https://msdn.microsoft.com/zh-cn/library/dd901590(VS.95).aspx I also recommend using the open source library DocumentFormat.OpenXml and the SpreadSheetDocument class for reading in a spreadsheet its much easier 我还建议使用开放源代码库DocumentFormat.OpenXml和SpreadSheetDocument类在电子表格中进行读取,这非常容易

 using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open("filename", false))
        {
            WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
            WorksheetPart workSheetPart = workbookPart.WorksheetParts.First();
            var sheetData = workSheetPart.Worksheet.Descendants<Row>();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM