473,753 Members | 6,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error while Excel file importing in .NET

18 New Member
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.Offic e.Interop.Excel .Workbooks.Open (String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPasswor d, Object IgnoreReadOnlyR ecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
AC_ESM.ESM_Addr essBookImportEx port.btnImport_ Click(Object sender, EventArgs e) +481
System.Web.UI.W ebControls.Link Button.OnClick( EventArgs e) +105
System.Web.UI.W ebControls.Link Button.RaisePos tBackEvent(Stri ng eventArgument) +107
System.Web.UI.W ebControls.Link Button.System.W eb.UI.IPostBack EventHandler.Ra isePostBackEven t(String eventArgument) +7
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +11
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +174
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +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)
{
FileUpLoadValid ator.Enabled = false;
Address addrDetails = new Address();

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

string fileName = "";
fileName = fUpload.PostedF ile.FileName.To String();

if(fileName == "")
fileName = fUpload.Resolve ClientUrl(fileN ame).ToString() ;

if (fileName == "")
fileName = fUpload.Resolve Url(fileName).T oString();

//open workbook
Microsoft.Offic e.Interop.Excel .Workbook theWorkbook = ExcelObj.Workbo oks.Open(fileNa me,
0,
false,
5,
"",
"",
true,
Microsoft.Offic e.Interop.Excel .XlPlatform.xlW indows,
"\t",
false,
false,
0,
true,
1,
0);
// get the collection of sheets in the workbook
Microsoft.Offic e.Interop.Excel .Sheets sheets = theWorkbook.Wor ksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Offic e.Interop.Excel .Worksheet worksheet = (Microsoft.Offi ce.Interop.Exce l.Worksheet)she ets.get_Item(1) ;
// loop through 10 rows of the spreadsheet and place each row in the list view

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

// Define the columns of the table.
dt.Columns.Add( new DataColumn("Las t_Name", typeof(string)) );
dt.Columns.Add( new DataColumn("Fir st_Name", typeof(string)) );
dt.Columns.Add( new DataColumn("Com pany", typeof(string)) );
dt.Columns.Add( new DataColumn("Cit y", typeof(string)) );
dt.Columns.Add( new DataColumn("Sta te", typeof(string)) );


for (int i = 2; i <= worksheet.Rows. Count; i++)
{
// get row value
Microsoft.Offic e.Interop.Excel .Range range = worksheet.get_R ange("B" + i.ToString(), "S" + i.ToString());
System.Array myvalues = (System.Array)r ange.Cells.Valu e2;

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

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

// get stateID from state name
IDataReader SReader = SPs.ACESMspGetS tateIdWithState Name(state).Get Reader();
int stateID =0;
if (SReader.Read() )
stateID = Convert.ToInt32 (SReader["StateID"].ToString());
SReader.Close() ;

// get CountryId from country name
IDataReader CReader = SPs.ACESMspGetC ountryIdWithCou ntryName(countr y).GetReader();
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.add Address(firstNa me, 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);

dgrdImportExpor t.Visible = true;
// clear dataGrid Value
dgrdImportExpor t.DataSource = null;
dgrdImportExpor t.DataBind();
dgrdImportExpor t.CurrentPageIn dex = 0;

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




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.42; ASP.NET Version:2.0.507 27.210
May 23 '07 #1
0 3006

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

Similar topics

1
3213
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 characters. When I import it into A2K, that field is truncated. If I try to inport the file into an EXISTING table that I define myself where that field is a MEMO field, the import crashes.
9
3920
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. There is no further explanation. What are the kinds of things that make this happen? Thanks from an obvious rookie. Gordon
1
2460
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 in fact five sheets in the Excel file. My original idea was to import the file into access and create a database file; which I did and worked beautifully. It generated five tables in the database as expected. However, I then thought why not...
3
3354
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 appending second file in last of the access table created earlier by importing data. thanks .plz help me.
1
3111
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 fields are laid out the same L-R and made certain that the data is the same in both the .xls file and the table it is to be imported to have the same data type in each field. I follow the File>Get External Data>Import path and choose the .xls...
1
1264
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"); Response.Charset = ""; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
7
12073
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
5894
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 facilitate my import process (It's all text columns, I perform transformations later). And I created a template in Excel to correspond to the table - essentially it's just column headers: In Excel, I've been opening files of work that we've done...
0
1609
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" standalone="yes"?> <ds_S3 xmlns="http://tempuri.org/ds_S3.xsd"> <tblTags> <StartDateAndTime>2000-01-01T00:00:00+01:00</StartDateAndTime> </tblTags>
0
9072
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8896
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9653
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9451
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9421
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6869
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4771
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2872
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.