首页 > 解决方案 > 有没有办法在 c# 中为 Oledb 找到异常详细信息?

问题描述

它工作正常,直到“ oleda.Fill(ds);”行 当调试器到达该行时,它不会显示任何错误或异常,只是返回到视图(HTML 页面)。我无法理解异常的来源。任何人都可以请指导我。

 public class OledbRepository
    {
        private string _connectionString;

        public OledbRepository(string filePath)
        {
            _connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';";
        }

        public DataTable Invoke(string sheetName)
        {
            DataTable result;

            using (var connection = new OleDbConnection(_connectionString))
            {
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM " + sheetName, connection);

                OleDbDataAdapter oleda = new OleDbDataAdapter() { SelectCommand = cmd };
                DataSet ds = new DataSet();
                oleda.Fill(ds);

                result = ds.Tables[0];
            }

            return result;
        }
    }

标签: c#datasetoledboledbconnection

解决方案


推荐阅读