tags:

views:

84

answers:

2

I have code

string conn = @"Provider=Microsoft.ACE.OLEDB.12.0;DSN=Excel Files;DBQ=" + strSheetPath + @";DriverId=1046;FIL=excel 12.0;MaxBufferSize=2048;PageTimeout=5;";
 //string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strSheetPath +";Extended Properties=Excel 12.0 Xml;HDR=YES;IMEX=1";
string destinationConnectionString = ConfigurationManager.ConnectionStrings["KGD6DBConnectionString"].ConnectionString;
string query = "Select * From [Sheet1$]";

using (var myConnection = new OleDbConnection(conn))
using (var destinationConnection = new SqlConnection(destinationConnectionString))
using (var bulkCopy = new SqlBulkCopy(destinationConnection))
{
    //Map first column in source to second column in sql table (skipping the ID column).
    //Excel schema[CompanyName,Phone] Table schema[ShipperID, CompanyName, Phone]
    bulkCopy.ColumnMappings.Add(0, 1);
    bulkCopy.ColumnMappings.Add(1, 2);
    bulkCopy.ColumnMappings.Add(2, 3);
    bulkCopy.ColumnMappings.Add(3, 4);
    bulkCopy.ColumnMappings.Add(4, 5);
    bulkCopy.ColumnMappings.Add(5, 6);
    bulkCopy.ColumnMappings.Add(6, 7);
    bulkCopy.ColumnMappings.Add(7, 8);
    bulkCopy.ColumnMappings.Add(8, 9);
    bulkCopy.ColumnMappings.Add(9, 10);
    bulkCopy.ColumnMappings.Add(10, 11);
    bulkCopy.ColumnMappings.Add(11, 12);
    bulkCopy.ColumnMappings.Add(12, 13);
    bulkCopy.ColumnMappings.Add(13, 14);
    bulkCopy.ColumnMappings.Add(14, 15);
    bulkCopy.ColumnMappings.Add(15, 16);
    bulkCopy.ColumnMappings.Add(16, 17);
    bulkCopy.ColumnMappings.Add(17, 18);
    bulkCopy.ColumnMappings.Add(18, 19);
    bulkCopy.ColumnMappings.Add(19, 20);
    bulkCopy.ColumnMappings.Add(20, 21);
    bulkCopy.ColumnMappings.Add(21, 22);
    bulkCopy.ColumnMappings.Add(22, 23);
    bulkCopy.ColumnMappings.Add(23, 24);

    bulkCopy.DestinationTableName = "dbo.sampleInventory";

    using (var myCommand = new OleDbCommand(query, myConnection))
    {
        myConnection.Open();
        destinationConnection.Open();

        var myReader = myCommand.ExecuteReader();
        while (myReader.Read())
        {
            bulkCopy.WriteToServer(myReader);
        }
    }
}
return (new DataTable());

getting error on connection opening line.

Error: Could not find installable ISAM.

A: 

Hi Lalit,

Make sure that you are building 32 bit application, otherwise is shouldn't work because Microsoft.ACE.OLEDB.12.0 is only for x86 platforms

If this doesn't help go to the http://support.microsoft.com/kb/209805

Muse VSExtensions
Ok, but how come i know i am building 32 bit application?? steps please
Lalit
For C# projects, you will find this option on the Project Properties dialog under the build tab. For VB.net projects, the setting is found on the Advanced Compiler Settings dialog which is made available via the Advanced Compile Options button on the Compile tab of the Project Properties. The list of available options are:1. Any CPU 2. x863. x64If you would like to see all available "processor architecture" download the following extension: http://visualstudiogallery.msdn.microsoft.com/en-us/36a6eb45-a7b1-47c3-9e85-09f0aef6e879
Muse VSExtensions
A: 

It looks like perhaps the component that allows Excel data to be queried as a database is missing or incorrectly registered on your machine.

There are some instructions at this link that may help: http://support.microsoft.com/kb/209805

Dan Puzey
I tried this, not working for me
Lalit