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?