【问题标题】:Read excel file using oledb in Script task在脚本任务中使用 oledb 读取 excel 文件
【发布时间】:2020-03-30 07:11:28
【问题描述】:

我正在尝试使用 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

如何解决这个问题?谢谢

【问题讨论】:

    标签: c# excel ssis oledbconnection script-task


    【解决方案1】:

    我使用 - excelSheetName = row["TABLE_NAME"].ToString(); 修复了它;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多