从excel导入到DB,并在MVC中使用EF从DB显示它们 [英] Import from excel to DB and the display them from DB using EF in MVC

查看:125
本文介绍了从excel导入到DB,并在MVC中使用EF从DB显示它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网页上传Excel文件并将数据保存到SQL数据库,然后从数据库中检索数据以表格格式显示在MVC中使用实体框架



Attendence的样本数据

SL。否

学生证

学生姓名

NIOS EnrolmentNo。

日期



我的尝试:



I want to upload Excel file from Webpage and save the data to SQL database and then retrieve the data from db to display in tabular format USING Entity Framework in MVC

Sample Data for Attendence
SL. No
Student ID
Student Name
NIOS EnrolmentNo.
Date

What I have tried:

S2Entities4 entities4 = new S2Entities4();
                foreach (DataRow row in dt.Rows)
                {

                    
                    entities4.Students.Add(new Student
                    {
                       // Student_Id = long.Parse(row["Student_Id"].ToString()),
                        Student_Name = row["Student_Name"].ToString(),
                        NIOS_Enrolment_No = row["NIOS_Enrolment_No"].ToString()
                                                                       
                    });
                }
                entities4.SaveChanges();







收到错误说明




Got Error Stating "

Column 'Student_Name' does not belong to table .'

推荐答案

如果不是必须的话在实时进程中,您可以创建一个SSIS包来导入上传的文件,创建一个SQL服务器作业来运行包,安排该作业每隔N分钟运行一次,然后让用户在网站上点击刷新想要。



我知道这听起来像是很多工作,但事实并非如此,这正是我自己接近它的方式。
If it doesn't have to be a real-time process, you could create an SSIS package to import the uploaded file, create a SQL server job to run the package, schedule that job to run every N minutes, and simply let the user hit refresh on the web site whenever he wants.

I know it sounds like a lot of work, but it really isn't, and that's precisely the way I would approach it myself.


您的样本数据的列名为学生姓名



您是试图从名为 Student_Name 的列中读取值。



这些不一样。第一个有空格,而第二个有下划线。



同样, NIOS_Enrolment_No 不是与 NIOS EnrolmentNo。相同。



您读取的列名称需要与以下列名称精确匹配源文件。调试代码并检查源文件中的实际列名,然后修复代码以使用正确的列名。
Your sample data has the column name "Student Name".

You are trying to read the value from a column called "Student_Name".

Those are not the same. The first has a space, whilst the second has an underscore.

Similarly, "NIOS_Enrolment_No" is not the same as "NIOS EnrolmentNo.".

The column names you read need to precisely match the column names from the source file. Debug your code and check the actual column names from the source file, and then fix your code to use the correct column names.


这篇关于从excel导入到DB,并在MVC中使用EF从DB显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆