473,595 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDb Problems Importing Excel Data

1 New Member
Folks,
I hope someone out there can please help me, not much hair left with this one.

I'm importing excel data into a SQL server database using an Oledb connection in C#. The problemm is that some of the rows returned to c# are giving null values, when there is a value in it in the original xl document. If you know what I mean.

Please help


DataTable dt=new DataTable();

string flread = ConfigurationSe ttings.AppSetti ngs["ExtractFil es"] + filetoread ;
string connectionStrin g = @"Provider=Micr osoft.Jet.OLEDB .4.0; Data Source=dsource; Extended Properties= ""Excel 8.0;HDR=NO;""";

connectionStrin g = connectionStrin g.Replace("dsou rce", flread);

try
{
OleDbDataAdapte r adapter = new OleDbDataAdapte r();

OleDbCommand selectCommand = new OleDbCommand();

selectCommand.C ommandText = selectcriteria;

OleDbConnection connec = new OleDbConnection ();

connec.Connecti onString = connectionStrin g;

selectCommand.C onnection = connec;

adapter.SelectC ommand = selectCommand;

adapter.Fill(dt );

adapter = null;
selectCommand = null;
connec = null;
Jan 31 '07 #1
2 2652
technocoder
1 New Member
I am facing same problem. Any workaround?

Folks,
I hope someone out there can please help me, not much hair left with this one.

I'm importing excel data into a SQL server database using an Oledb connection in C#. The problemm is that some of the rows returned to c# are giving null values, when there is a value in it in the original xl document. If you know what I mean.

Please help


DataTable dt=new DataTable();

string flread = ConfigurationSe ttings.AppSetti ngs["ExtractFil es"] + filetoread ;
string connectionStrin g = @"Provider=Micr osoft.Jet.OLEDB .4.0; Data Source=dsource; Extended Properties= ""Excel 8.0;HDR=NO;""";

connectionStrin g = connectionStrin g.Replace("dsou rce", flread);

try
{
OleDbDataAdapte r adapter = new OleDbDataAdapte r();

OleDbCommand selectCommand = new OleDbCommand();

selectCommand.C ommandText = selectcriteria;

OleDbConnection connec = new OleDbConnection ();

connec.Connecti onString = connectionStrin g;

selectCommand.C onnection = connec;

adapter.SelectC ommand = selectCommand;

adapter.Fill(dt );

adapter = null;
selectCommand = null;
connec = null;
Feb 16 '07 #2
kenobewan
4,871 Recognized Expert Specialist
First problem is that you appear to be using the OLEDB connection for Access rather than SQL Server. Check out - Connection Strings .
Feb 18 '07 #3

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

Similar topics

3
5070
by: Wade G. Pemberton | last post by:
Help!: I use javascript to format repetitive data from a web page input FORM into a long string , and save it as lines of comma delimited data in a text file on a Unix server. The text file is meant to be downloaded to MS Excel on the users' computers. Several such files will be downloaded and appended into the Excel file. Problem: The text file looks good when viewed offline by any text reader, but Excel will not import it...
2
3595
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records that are "dirty" i.e. the field contents do not comply with the expected format (date/time) and they end up in a seperate table of import errors. (The records in "error" are actually empty fields.) This is a regular event and I do not want to...
7
11603
by: aacool | last post by:
Hi, I've been trying to open an Excel connection through OLEDB with the code below: string ConnectString =@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + fileName.Text + ";ExtendedProperties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = ConnectString; conn.Open();
4
2156
by: [Yosi] | last post by:
I working with Excel file by using the OLEDB components such : OleDbConnection ,OleDbCommand. I successfuly read/update the Excel table. The problem is how can I change the color of spicific location, I can update spicifc value by somthing like : _oleCmdUpdate =new OleDbCommand( @" Update set F1=" + strVal, _oleConn); How can I change color this spicific location in Excel table, I find somthing in VB not C# , any one can convert tho...
9
3375
by: Brian Hanson | last post by:
Hi, I have an unusual problem that just showed its ugly head at a pretty bad time. I have an asp.net (VB) app that takes data from an Excel sheet and puts it into SQL Server. I get the data out of Excel using OleDB, and suddenly, some of the data was not being extracted from Excel. I use OleDb for the extract into a DataTable and from there an SqlClient.SqlCommand to put it into SQL Server.
4
1894
by: Claud Balls | last post by:
I've been butting heads with this code, it always errors at objAdapter1.Fill(objDataTable1) Is oledb the best way to do this? How about ADO.NET? Dim objDataTable1 As DataTable Dim objConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _ & strFilePath & ";Extended Properties=Excel 8.0") objConn.Open() Dim strCmd As String = String.Format("SELECT * FROM ")
2
3489
by: madeleine | last post by:
I'm hoping the answer to this is that I'm just doing something silly, but I'm really scratching my head over this one. I'm importing data from multiple workbooks, each workbook has a sheet called SubSAT and I need to get specific data from that into the database. I'm finding that if I have the workbook open on my desktop then the SubSAT % complete and the High level plan % come in fine, but as soon as the workbook is closed they come...
5
3161
by: hharriel | last post by:
Hi, I am hoping someone can help me with an issue I am having with excel and ms access. I have collected data (which are in individual excel files) from 49 different school districts. All districts have used the same excel template and populated the same 32 data fields (columns). I created one large excel file from all 49 files which gives me a master table of 60,000 or so records. I have tried to import this master table into access...
3
2997
by: scoots987 | last post by:
What do others do if you need to import excel files into SQL Server? My main problems are 1) zipcode formatting issues. If the column is a mix of zip and zip+4, I have problems retrieving all zipcodes. 2) If the last column contains NULL no information is imported. All this with using the Management console using Import data in SQL Server 2005. I am simply trying to import the data into NEW databases.
0
7955
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
8261
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...
1
8019
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,...
0
6674
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5839
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
5418
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
3911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.