C# VS 2015:获得;引发异常:';System.Data.OleDb.OleDbException';在System.Data.dll中“;尝试连接到Excel时

C# VS 2015:获得;引发异常:';System.Data.OleDb.OleDbException';在System.Data.dll中“;尝试连接到Excel时,c#,ado.net,visual-studio-2015,oledb,oledbexception,C#,Ado.net,Visual Studio 2015,Oledb,Oledbexception,好的,这是我的代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb;

好的,这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace DisplayingDataFromExcelSheets
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string datasource = @"C:\Users\E180728\Documents\FakeGradesTable.xlsx";
            string cs = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + datasource + ";Extended Properties='Excel 12.0;HDR=YES'";
            OleDbConnection cn = new OleDbConnection(cs);
            Console.WriteLine("Connecting to: " + cs);
            OleDbDataAdapter da = new OleDbDataAdapter("select * from [marks$]", cn);
            DataSet ds = new DataSet();
            da.Fill(ds, "marks");
            dataGridView1.DataSource = ds.Tables[0];

        }
    }
}
当我尝试运行此操作时,表单会显示一个空白的DataGridView,输出中将显示以下内容:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace DisplayingDataFromExcelSheets
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string datasource = @"C:\Users\E180728\Documents\FakeGradesTable.xlsx";
            string cs = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + datasource + ";Extended Properties='Excel 12.0;HDR=YES'";
            OleDbConnection cn = new OleDbConnection(cs);
            Console.WriteLine("Connecting to: " + cs);
            OleDbDataAdapter da = new OleDbDataAdapter("select * from [marks$]", cn);
            DataSet ds = new DataSet();
            da.Fill(ds, "marks");
            dataGridView1.DataSource = ds.Tables[0];

        }
    }
}
'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U 32\mscorlib\v4.0.0.0\UU b77a5c561934e089\mscorlib.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\assembly\GAC\MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\14.0.0.0_uuB03F5F7F11D50A3A\Microsoft.VisualStudio.HostingProcess.Utilities.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.windows.Forms\v4.0.0\UU b77a5c561934e089\System.windows.Forms.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。 'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System\v4.0.0.0\UU b77a5c561934e089\System.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.Drawing\v4.0.0\UU b03f5f7f11d50a3a\System.Drawing.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

“DisplayingDataFromExcelSheets.vshost.exe”(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载了“C:\windows\assembly\GAC\MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\14.0.0\uu b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll”。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\assembly\GAC\U MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0_uB03F5F7F11D50A3A\Microsoft.VisualStudio.Debugger.Runtime.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\Users\E180728\Documents\Visual Studio 2015\Projects\ADOProject\DisplayingDataFromExcelSheets\bin\Debug\DisplayingDataFromExcelSheets.vshost.exe'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.Core\v4.0.0.0\UU b77a5c561934e089\System.Core.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.Xml.Linq\v4.0\U 4.0.0\UU B77A561934E089\System.Xml.Linq.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.Data.DataSetExtensions\v4.0.0\UUU b77a5c561934e089\System.Data.DataSetExtensions.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\Microsoft.CSharp\v4.0.0.0\uu b03f5f7f11d50a3a\Microsoft.CSharp.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U 32\System.Data\v4.0.0.0\UU b77a5c561934e089\System.Data.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.Deployment\v4.0.0\UU b03f5f7f11d50a3a\System.Deployment.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.Net.Http\v4.0.0.0\UU b03f5f7f11d50a3a\System.Net.Http.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\windows\Microsoft.Net\assembly\GAC\U MSIL\System.Xml\v4.0\U 4.0.0\UU b77a5c561934e089\System.Xml.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用

线程0x3218已退出,代码为0(0x0)。 线程0x2b8c已退出,代码为0(0x0)

'DisplayingDataFromExcelSheets.vshost.exe'(CLR v4.0.30319:DisplayingDataFromExcelSheets.vshost.exe):加载'C:\Users\E180728\Documents\Visual Studio 2015\Projects\ADOProject\DisplayingDataFromExcelShee