Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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 .'
"
Posted
Updated 3-Oct-18 6:15am
v2

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.
 
Share this answer
 
v2
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900