473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

error while Excel file importing in .NET

18
Hi All,

I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me.

Exception from HRESULT: 0x800A03EC
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[COMException (0x800a03ec): Exception from HRESULT: 0x800A03EC]
Microsoft.Office.Interop.Excel.Workbooks.Open(Stri ng Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
AC_ESM.ESM_AddressBookImportExport.btnImport_Click (Object sender, EventArgs e) +481
System.Web.UI.WebControls.LinkButton.OnClick(Event Args e) +105
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String eventArgument) +107
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


I am attaching the code also.

/// <summary>
/// import data from Excel sheet to database
/// and also displays the same in datagrid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
FileUpLoadValidator.Enabled = false;
Address addrDetails = new Address();

// get excel file from which data need to import to dataGrid

string fileName = "";
fileName = fUpload.PostedFile.FileName.ToString();

if(fileName == "")
fileName = fUpload.ResolveClientUrl(fileName).ToString();

if (fileName == "")
fileName = fUpload.ResolveUrl(fileName).ToString();

//open workbook
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(fileName,
0,
false,
5,
"",
"",
true,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindow s,
"\t",
false,
false,
0,
true,
1,
0);
// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.g et_Item(1);
// loop through 10 rows of the spreadsheet and place each row in the list view

System.Data.DataTable myDt = new System.Data.DataTable();
try
{
// Create sample data for the DataGrid control.
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;

// Define the columns of the table.
dt.Columns.Add(new DataColumn("Last_Name", typeof(string)));
dt.Columns.Add(new DataColumn("First_Name", typeof(string)));
dt.Columns.Add(new DataColumn("Company", typeof(string)));
dt.Columns.Add(new DataColumn("City", typeof(string)));
dt.Columns.Add(new DataColumn("State", typeof(string)));


for (int i = 2; i <= worksheet.Rows.Count; i++)
{
// get row value
Microsoft.Office.Interop.Excel.Range range = worksheet.get_Range("B" + i.ToString(), "S" + i.ToString());
System.Array myvalues = (System.Array)range.Cells.Value2;

// Convert row value of Excel sheet to 1-D array
string[] theArray = ConvertToStringArray(myvalues);

// ensure that row has data
if ((theArray.GetValue(0).ToString() != string.Empty) || (theArray.GetValue(1).ToString() != string.Empty) || (theArray.GetValue(2).ToString() != string.Empty) || (theArray.GetValue(3).ToString() != string.Empty))
{
string firstName = theArray.GetValue(0).ToString();
string middleName = theArray.GetValue(1).ToString();
string lastName = theArray.GetValue(2).ToString();
string company = theArray.GetValue(3).ToString();
string city = theArray.GetValue(4).ToString();
string state = theArray.GetValue(5).ToString();
string country = theArray.GetValue(6).ToString();
string address1 = theArray.GetValue(7).ToString();
string address2 = theArray.GetValue(8).ToString();
string zipCode = theArray.GetValue(9).ToString();
string phHome = theArray.GetValue(10).ToString();
string phBusins = theArray.GetValue(11).ToString();
string phMobile = theArray.GetValue(12).ToString();
string fax = theArray.GetValue(13).ToString();
string email = theArray.GetValue(14).ToString();
string webUrl = theArray.GetValue(15).ToString();
string jTitle = theArray.GetValue(16).ToString();
string notes = theArray.GetValue(17).ToString();

// get stateID from state name
IDataReader SReader = SPs.ACESMspGetStateIdWithStateName(state).GetReade r();
int stateID =0;
if (SReader.Read())
stateID = Convert.ToInt32(SReader["StateID"].ToString());
SReader.Close();

// get CountryId from country name
IDataReader CReader = SPs.ACESMspGetCountryIdWithCountryName(country).Ge tReader();
int countryID =0;
if (CReader.Read())
countryID = Convert.ToInt32(CReader["CountryID"].ToString());
CReader.Close();

// insert row value into new row of dataTable
dr = dt.NewRow();

dr[0] = lastName;
dr[1] = firstName;
dr[2] = company;
dr[3] = city;
dr[4] = state;

// add dataRow to dataTable
dt.Rows.Add(dr);

// insert each row values to contact table
addrDetails.addAddress(firstName, middleName, lastName, email, address1, address2, string.Empty, city, string.Empty, countryID, stateID, zipCode, fax, phHome, phBusins, phMobile, webUrl, jTitle, company, notes);
}
else
break;
}

// ensure that dataTable has values
if (dt.Rows.Count > 0)
{
// assign dataTable to DataView
DataView dv = new DataView(dt);

dgrdImportExport.Visible = true;
// clear dataGrid Value
dgrdImportExport.DataSource = null;
dgrdImportExport.DataBind();
dgrdImportExport.CurrentPageIndex = 0;

// bind excel sheet values to dataGrid
dgrdImportExport.DataSource = dv;
dgrdImportExport.DataBind();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
May 23 '07 #1
0 2976

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Richard Holliingsworth | last post by:
Hello: Thanks for your quick response. I'm trying to import a new Excel file into an A2K table and it's truncating the data. One of the Excel columns is a text field that can be up to 2000...
9
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. ...
1
by: Geoff Jones | last post by:
Hi I have a question which I hope somebody can answer. I have written a VB application with which I want to import an Excel file, analyze the data within it and do some calculations. There are...
3
by: mukeshsrivastav | last post by:
dear sir i want to move form excel to access. i have 5 excel file having same formats and fields.now i want to import all data in one access table. importing one file is easy .but importing and...
1
by: puremetal33 | last post by:
I have worked very little with Access and have hit a snag. My task right now is to import the data from a spreadsheet into an existing table in an Access database. I edited the .xls file so that...
1
by: coolcoder2007 | last post by:
Hi, I have Exported some data in a Excel file using this code- Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=dependencymatrix.xls"); ...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
5
geolemon
by: geolemon | last post by:
Import text wizard says: I'm banging my head on this one, here's why: I've been importing files using this process and data format, with success! I created a temporary table in Access to...
0
by: James Minns | last post by:
Hi all, I have a problem with Excel 2007: it crashes when importing certain xml data, exported from another software This is the smallest file which reproduces the problem: <?xml version="1.0"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.