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 9305399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:55:12+00:00 2026-06-18T23:55:12+00:00

I have developed an asp.net application in which input will be given through an

  • 0

I have developed an asp.net application in which input will be given through an excel sheet.
This application is working fine in a system with WINDOWS XP and MS office 2008.
If i try to run the same application in a system with WINDOWS 7 and MS office 2010 i am getting a Argument Null Exception.

Code:

foreach (var dr in data)
            {
                LHSupdate = new LHSUpdate();
                if (!string.IsNullOrEmpty(Convert.ToString(dr["Associate Id"])))
                {
                    AssociateID = Convert.ToString(dr["Associate Id"]);
                }
                LHSupdate.AssciateID = AssociateID;
                if (!string.IsNullOrEmpty(Convert.ToString(dr["Associate Name"])))
                {
                    AssociateName = Convert.ToString(dr["Associate Name"]);
                }
                LHSupdate.Name = AssociateName;

                var designation = dsData.Tables["LHS"].AsEnumerable().Where(r => Convert.ToString(r["Associate Id"]).Trim() == LHSupdate.AssciateID.Trim());

                if (designation != null)
                {
                    foreach (var de in designation)
                    {
                        LHSupdate.Designation = Convert.ToString(de["Level"]);
                    }
                }

                else
                {
                    LHSupdate.Designation = "";
                }                
                LHSupdate.CourseName = Convert.ToString(dr["Trainings "]);
                LHSupdate.CourseStatus = Convert.ToString(dr["Training Status"]);
                LHSupdate.Score = Convert.ToString(dr["Credits"]);
                LHSupdate.LearningMode = Convert.ToString(dr["Venue"]);
                LHSupdate.StartDate = Convert.ToString(dr["Start Date"]);
                LHSupdate.EndDate = Convert.ToString(dr["End Date"]);                
                lstLHS.Add(LHSupdate);
            }

I am getting error in the line:

var designation = dsData.Tables["LHS"].AsEnumerable().Where(r => Convert.ToString(r["Associate Id"]).Trim() == LHSupdate.AssciateID.Trim());

Code:

private DataSet Getdata()
        {
            string connectionString = "";
            string getExcelSheetName = string.Empty;
            if (fuLHSEntry.HasFile)
            {
                string fileName = Path.GetFileName(fuLHSEntry.PostedFile.FileName);
                string fileExtension = Path.GetExtension(fuLHSEntry.PostedFile.FileName);
                string fileLocation = Server.MapPath("~/App_Data/" + fileName);
                fuLHSEntry.SaveAs(fileLocation);

                if (fileExtension == ".xls")
                {
                    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + @";Extended Properties=" + Convert.ToChar(34).ToString() + @"Excel 8.0;Imex=1;HDR=Yes;" + Convert.ToChar(34).ToString();
                }
                else if (fileExtension == ".xlsx" || fileExtension == ".xlsm")
                {
                    connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + @";Extended Properties=" + Convert.ToChar(34).ToString() + @"Excel 12.0;IMEX=2;HDR=Yes;" + Convert.ToChar(34).ToString();
                }

                OleDbConnection con = new OleDbConnection(connectionString);
                OleDbCommand cmd = new OleDbCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.Connection = con;
                OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
                DataTable dtExcelRecords = new DataTable();
                con.Open();
                DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                int count = 0;
                foreach (DataRow dr in dtExcelSheetName.Rows)
                {
                    getExcelSheetName = GetSheetName(dr);
                    if (!string.IsNullOrEmpty(getExcelSheetName))
                    {                        
                        cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
                        dAdapter.SelectCommand = cmd;
                        if (getExcelSheetName.ToUpper().Contains("LEARNING"))
                        {
                            getExcelSheetName = "LEARNING";
                        }
                        else
                        {
                            getExcelSheetName = "LHS";
                        }
                        dAdapter.Fill(dsData, getExcelSheetName);
                        count++;
                        if (count == 2)
                        {
                            break;
                        }
                    }
                }
                con.Close();
            }
            return dsData;
        }

Please help me in resolving this issue.
Thanks,
Raji

  • 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-18T23:55:14+00:00Added an answer on June 18, 2026 at 11:55 pm

    From your code it appears that the table can have two possible names.

    Either give it always the same name that you’re using later when reading:

    dAdapter.Fill(dsData, "LHS");
    

    Or you can take the table by index ignoring its name altogether:

    var designation = dsData.Tables[0].AsEnumerable().Where(r => Convert.ToString(r["Associate Id"]).Trim() == LHSupdate.AssciateID.Trim());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed an application in ASP.NET 3.5 which utilizes the Membership and Roles
We have an ASP.NET MVC application for which we have developed our own custom
I have an old ASP.NET web application on a server, which was developed in
I have developed a web application in asp.net, there is a page in this
I have developed an ASP.NET application on Visual studio 2010, which takes user details(
I have developed an ASP.NET MVC (version 2 RC) application with a ton of
i have developed a web application asp.net C#. on a button click i am
I have developed a MVC web application with ASP.NET MVC and im just wondering
I have a web application developed in ASP.NET 2.0, deployed in a data center.
I have a ASP.net 3.5 web application developed in VB.net I am using iTextsharp

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.