Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8511089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:53:28+00:00 2026-06-11T03:53:28+00:00

I am Uploading an Excel file and after reading that file getting result in

  • 0

I am Uploading an Excel file and after reading that file getting result in this.

 var data = from c in excel.Worksheet<QuestionMaster>()
            select new
            {
              c.Questionname,
              c.Answer1,
              c.Answer2,
              c.Answer3,
              c.Answer4,
              c.CorrectAnswer,
            };

Now I need to check that any of the Column in uploaded data should not be null

For that My Code is:
Question Master is the Model Class

QuestionMaster questions = new QuestionMaster();
QuestionMaster temp = new QuestionMaster();
List<QuestionMaster> ques = new List<QuestionMaster>();//
  foreach (var item in data)
   {
      int i = 0;
     if (item.Questionname == null || item.Answer1 == null || item.Answer2 == null ||   item.Answer3 == null || item.Answer4 == null || item.CorrectAnswer == null)
      {
          if (item.Questionname != null)
           temp.Questionname = item.Questionname.Trim();                            
         else
           temp.Questionname = "Question Name not Found in Uploaded Excel File";                            
         if (item.Answer1 != null)
           temp.Answer1 = item.Answer1.Trim();                            
         else
           temp.Answer1 = "Answer 1 Not Found in Uploaded Excel File";                            
                       \\Some more Couple of If-Else Conditions

ques.Add(temp);
      }

Now the Problem is :
Suppose I got three Different Rows in which their are Some Null Columns and the above conditions got true.

When ques.add(temp) runs 2nd or 3rd Time it overwrite the other previously added List Items but the count of the number of the items added in the List remain same.
It means it is overwriting the whole list with the current data in the temp.

Please tell me where I am getting wrong.

Thanks in Advance!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:53:30+00:00Added an answer on June 11, 2026 at 3:53 am

    you need to be creating a new object in your loop every time, currently it’s outside your loop so the original object keeps changing

      foreach (var item in data)
       {
         QuestionMaster temp = new QuestionMaster();
    
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm uploading an Excel file and then reading data using oledb connection in asp.net
i am having an form for uploading an excel file like <form enctype=multipart/form-data action=http://localhost/joomla/Joomla_1.5.7/index.php?option=com_jumi&fileid=7
Can anyone give me some idea about uploading data from excel to access database
I am uploading data from Excel to SQL Server using the following structure: Private
I have data from an Excel spreadsheet that I want to import into a
When uploading an excel file I am receiving this error, can anyone help me?
I am currently able to enter csv file data into Excel VBA by uploading
I am looking for best practice for uploading excel data in Sql server 2000
I am uploading an Excel having 5 sheets. While uploading i am getting the
I have a set of data which needs to be imported from a excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.