472,978 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,978 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 2943

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.