0
このコードは私のマシンでは完璧に動作しますが(2010年には優れています)、スーパーバイザーが実行しようとしたが、エクセル2016接続を変更する必要がありますか?ConStr = "プロバイダ= Microsoft.ACE.OLEDB.12.0;データソース=" + fileFullPath + ";拡張プロパティ= \" Excel 12.0; HDR = "+ HDR +"; IMEX = 0 \ "";複数のシートをexcel(2016)ファイルにロードする方法
string FolderPath = Dts.Variables["User::FolderPath"].Value.ToString();
string TableName = Dts.Variables["User::TableName"].Value.ToString();
string SchemaName = Dts.Variables["User::SchemaName"].Value.ToString();
string SheetNameToLoad = Dts.Variables["User::SheetNameLike"].Value.ToString();
var directory = new DirectoryInfo(FolderPath);
FileInfo[] files = directory.GetFiles();
//Declare and initilize variables
string fileFullPath = "";
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)(Dts.Connections["DBconnection"].AcquireConnection(Dts.Transaction) as SqlConnection);
////Get one Book(Excel file at a time)
foreach (FileInfo file in files)
{
fileFullPath = FolderPath + "\\" + file.Name;
MessageBox.Show(fileFullPath);
// //Create Excel Connection
string ConStr;
string HDR;
HDR = "YES";
ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileFullPath + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";
OleDbConnection cnn = new OleDbConnection(ConStr);
// //Get Sheet Name
cnn.Open();
DataTable dtSheet = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string sheetname;
sheetname = "";
//Only read data from provided SheetNumber
foreach (DataRow drSheet in dtSheet.Rows)
{
sheetname = drSheet["TABLE_NAME"].ToString();
MessageBox.Show(sheetname);
//Load the Data if Sheet Name contains value of SheetNameLike
if (sheetname.Contains(SheetNameToLoad) == true)
{
//Load the DataTable with Sheet Data so we can get the column header
OleDbCommand oconn = new OleDbCommand("select * from [" + sheetname + "] where CityName ='ARLINGTON'", cnn);
OleDbDataAdapter adp = new OleDbDataAdapter(oconn);
DataTable dt = new DataTable();
adp.Fill(dt);
cnn.Close();
//Load Data from DataTable to SQL Server Table.
using (SqlBulkCopy BC = new SqlBulkCopy(myADONETConnection))
{
BC.DestinationTableName = SchemaName + "." + TableName;
BC.WriteToServer(dt);
}
}
}
うん、私はすでに彼のマシンはまだ同じエラーを取得上のMicrosoft Accessデータベースエンジン2010再頒布可能パッケージをダウンロードしてください。 ace.oledb.12はまだ2016のExcelで動作しますか?@ LONG – Rab
完全なエラーメッセージを貼り付けることはできますか? ACE.OLEDB.12.0と表示されている場合、2016はインストールされていませんが、それが表示されている場合は正しいバージョン(32ビットまたは64ビット)をダウンロードして再インストールしてからリブートする必要があります。 – LONG
例外がスローされました呼び出しのターゲット。しかし彼のマシンをチェックしたところ、ace.oledb.12.0はインストールされていませんでしたが、まだインストールされていましたが、同じエラーが表示される@LONG – Rab