我正在尝试在SSIS的脚本任务中使用oledb命令从Excel读取数据。 excel没有工作表名称。工作表名称为空,出现错误。下面是使用的代码
excelConnection = new OleDbConnection(excelConnectionString);
excelConnection.Open();
DataTable excelDataTable = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string excelSheetName = string.Empty;
foreach (DataRow row in excelDataTable.Rows)
{
excelSheetName = row[0].ToString().Trim("'".ToCharArray());
//Console.writeLine(excelSheetName);
}
OleDbDataAdapter excelAdapter = new OleDbDataAdapter();
OleDbCommand excelCommand = new OleDbCommand();
DataSet excelDataSet = new DataSet();
excelCommand.Connection = excelConnection;
excelCommand.CommandText = "Select * from [" + excelSheetName + "]";
excelAdapter.SelectCommand = excelCommand;
excelAdapter.Fill(excelDataSet); // error here
如何解决?谢谢
我使用-excelSheetName = row [“ TABLE_NAME”]。ToString();]修复了它>