Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,615 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 973 people online right now. Registration is fast and FREE... Join Now!




C#- Console AppThe Microsoft Jet database engine could not find the ob

 
Reply to this topicStart new topic

C#- Console AppThe Microsoft Jet database engine could not find the ob, OleDbException was Unhandled

godharaj
post 12 Oct, 2008 - 03:09 PM
Post #1


New D.I.C Head

*
Joined: 12 Oct, 2008
Posts: 4

csharp
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;

namespace ExcelParser
{
class Program
{
static string sSourceFile = ConfigurationManager.AppSettings["XLSfile"];
static string sFile = ConfigurationManager.AppSettings["TextFile"];
static StreamWriter swTXT = new StreamWriter(sFile);
static void Main(string[] args)
{
WriteConsoleLog("Start of the Script");
// DataSet returnDataObject = new DataSet();

OleDbConnection ConnExcel;
OleDbDataAdapter AdapterExcel;

ConnExcel = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= XSPsource;Extended Properties=Excel 8.0;");
ConnExcel.Open();

DataTable returnDataObject = new DataTable();
OleDbCommand selectCommand = new OleDbCommand("select * from [" + sSourceFile + "]");

selectCommand.Connection = ConnExcel;
AdapterExcel = new OleDbDataAdapter();
AdapterExcel.SelectCommand = selectCommand;
AdapterExcel.Fill(returnDataObject);

for (int i = 0; i < returnDataObject.Rows.Count; i++)
{
swTXT.WriteLine(returnDataObject.Rows[i].ItemArray[0].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[1].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[2].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[3].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[4].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[5].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[6].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[7].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[8].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[9].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[10].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[11].ToString());
}
}


}
}


App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="C:\CRD-Projects\Config\CRDMasterDEV.config">
<add key="XLSfile" value="CA_Data_093008.xls"></add>
</appSettings>
</configuration>


ERROR:- The Microsoft Jet database engine could not find the object 'CA_Data_093008.xls'. Make sure the object exists and that you spell its name and the path name correctly.

What am I doing wrong here?
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 12 Oct, 2008 - 03:36 PM
Post #2


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,439



Thanked 94 times

Dream Kudos: 2625

Expert In: ruling the world.

My Contributions


Moved to C# smile.gif
User is online!Profile CardPM

Go to the top of the page

baavgai
post 12 Oct, 2008 - 03:50 PM
Post #3


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,967



Thanked 96 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


Always give full paths, so "C:\...\CA_Data_093008.xls".

Also, for your loop, you might try something like this:
csharp

foreach(DataRow row in returnDataObject.Rows) {
string s = "";
for (int i = 0; i < row.ItemArray.Length; i++) {
if (i>0) { s += "|"; }
object item = row.ItemArray[i];
if (item!=null) { s += item.ToString(); }
}
swTXT.WriteLine(s);
}

User is offlineProfile CardPM

Go to the top of the page

godharaj
post 12 Oct, 2008 - 06:13 PM
Post #4


New D.I.C Head

*
Joined: 12 Oct, 2008
Posts: 4

The Absolute Path Name of Source Excel file did NOT work.
I think I am Missing something here.

Thanks for the Loop suggestion, baavgai.

--------------------------------------------------------------------------------------


QUOTE(godharaj @ 12 Oct, 2008 - 04:09 PM) *

csharp
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;

namespace ExcelParser
{
class Program
{
static string sSourceFile = ConfigurationManager.AppSettings["XLSfile"];
static string sFile = ConfigurationManager.AppSettings["TextFile"];
static StreamWriter swTXT = new StreamWriter(sFile);
static void Main(string[] args)
{
WriteConsoleLog("Start of the Script");
// DataSet returnDataObject = new DataSet();

OleDbConnection ConnExcel;
OleDbDataAdapter AdapterExcel;

ConnExcel = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= XSPsource;Extended Properties=Excel 8.0;");
ConnExcel.Open();

DataTable returnDataObject = new DataTable();
OleDbCommand selectCommand = new OleDbCommand("select * from [" + sSourceFile + "]");

selectCommand.Connection = ConnExcel;
AdapterExcel = new OleDbDataAdapter();
AdapterExcel.SelectCommand = selectCommand;
AdapterExcel.Fill(returnDataObject);

for (int i = 0; i < returnDataObject.Rows.Count; i++)
{
swTXT.WriteLine(returnDataObject.Rows[i].ItemArray[0].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[1].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[2].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[3].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[4].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[5].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[6].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[7].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[8].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[9].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[10].ToString() + "|" +
returnDataObject.Rows[i].ItemArray[11].ToString());
}
}


}
}


App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="C:\CRD-Projects\Config\CRDMasterDEV.config">
<add key="XLSfile" value="CA_Data_093008.xls"></add>
</appSettings>
</configuration>


ERROR:- The Microsoft Jet database engine could not find the object 'CA_Data_093008.xls'. Make sure the object exists and that you spell its name and the path name correctly.

What am I doing wrong here?

User is offlineProfile CardPM

Go to the top of the page

baavgai
post 13 Oct, 2008 - 02:56 AM
Post #5


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,967



Thanked 96 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


QUOTE(godharaj @ 12 Oct, 2008 - 10:13 PM) *

I think I am Missing something here.


Yep, you are. I just noticed you're using the filename, not the worksheet name, in your select.

Here's an example of what you're trying to do: http://free.netartmedia.net/CSharp/CSharp22.html
User is offlineProfile CardPM

Go to the top of the page

godharaj
post 13 Oct, 2008 - 05:56 PM
Post #6


New D.I.C Head

*
Joined: 12 Oct, 2008
Posts: 4

QUOTE(baavgai @ 13 Oct, 2008 - 03:56 AM) *

QUOTE(godharaj @ 12 Oct, 2008 - 10:13 PM) *

I think I am Missing something here.


Yep, you are. I just noticed you're using the filename, not the worksheet name, in your select.

Here's an example of what you're trying to do: http://free.netartmedia.net/CSharp/CSharp22.html
User is offlineProfile CardPM

Go to the top of the page

godharaj
post 13 Oct, 2008 - 06:01 PM
Post #7


New D.I.C Head

*
Joined: 12 Oct, 2008
Posts: 4

Hey baavgai,

This worked.

Thanks for your help.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:55AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month