By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,504 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

OleDb Problems Importing Excel Data

P: 1
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 = ConfigurationSettings.AppSettings["ExtractFiles"] + filetoread ;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=dsource;Extended Properties= ""Excel 8.0;HDR=NO;""";

connectionString = connectionString.Replace("dsource", flread);

try
{
OleDbDataAdapter adapter = new OleDbDataAdapter();

OleDbCommand selectCommand = new OleDbCommand();

selectCommand.CommandText = selectcriteria;

OleDbConnection connec = new OleDbConnection();

connec.ConnectionString = connectionString;

selectCommand.Connection = connec;

adapter.SelectCommand = selectCommand;

adapter.Fill(dt);

adapter = null;
selectCommand = null;
connec = null;
Jan 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: 1
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 = ConfigurationSettings.AppSettings["ExtractFiles"] + filetoread ;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=dsource;Extended Properties= ""Excel 8.0;HDR=NO;""";

connectionString = connectionString.Replace("dsource", flread);

try
{
OleDbDataAdapter adapter = new OleDbDataAdapter();

OleDbCommand selectCommand = new OleDbCommand();

selectCommand.CommandText = selectcriteria;

OleDbConnection connec = new OleDbConnection();

connec.ConnectionString = connectionString;

selectCommand.Connection = connec;

adapter.SelectCommand = selectCommand;

adapter.Fill(dt);

adapter = null;
selectCommand = null;
connec = null;
Feb 16 '07 #2

kenobewan
Expert 2.5K+
P: 4,871
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

Post your reply

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