1

I am trying to read data from Excel using the oledb command in the script task of SSIS. The excel does not have sheet names. I am getting error as the sheet name is empty. Below is the code used

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

How to fix this? Thanks

1 Answer 1

1

I fixed it using - excelSheetName = row["TABLE_NAME"].ToString();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.