Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

c# reading data from .xls file results in missing data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ebenl555@hotmail.com - 11 Jan 2008 07:36 GMT
i am writing code to import data from an .xls file into a db using an
oledbadapter to fill a datatable. I can access most of the values
easily using this method. i do however have problems with a couple of
lines in the file. when i access these rows, they do not contain any
data. when i look at the file, the only difference that i can see is
that these problematic rows have merged cells. i have played around
with the merging and unmerging and it does not seem to have made a
problem.

when the first column is merged with x amount of columns, i can only
see the values for the columns following the first. anybody have an
idea why this might be happening?

the code for filling the data table is below

// gets the sheet name from the web.config file

string sheet2 =
System.Configuration.ConfigurationManager.AppSettings["SMARTDocSheet2"].ToString();

// Set up a new connection for the Excel file which was uploaded (will
be read like a table)

System.Data.OleDb.OleDbConnection lConn = new OleDbConnection();

lConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" + filePath + "; Extended Properties=\"Excel 8.0;HDR=No\";";

try

{

lConn.Open();

OleDbCommand command = new OleDbCommand("SELECT * FROM [" + sheet2 +
"$]", lConn);

// read the first sheet as a new table

OleDbDataAdapter daAllData = new OleDbDataAdapter(command);

DataTable table1 = new DataTable();

daAllData.Fill(table1);

}
ebenl555@hotmail.com - 11 Jan 2008 08:32 GMT
On Jan 11, 9:36 am, ebenl...@hotmail.com wrote:
> i am writing code to import data from an .xls file into a db using an
> oledbadapter to fill a datatable. I can access most of the values
[quoted text clipped - 44 lines]
>
> - Show quoted text -

I managed to solve my problem by modifiying the connection string to
include the IMEX property and set the value to 1. I am not yet sure
what exactly this does, but it has solve my problem. Will investigate
when i have the time.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.