Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用axSpreadsheet控件设置源时发生强制转换错误_C#_Excel_Casting_Oledb - Fatal编程技术网

C# 使用axSpreadsheet控件设置源时发生强制转换错误

C# 使用axSpreadsheet控件设置源时发生强制转换错误,c#,excel,casting,oledb,C#,Excel,Casting,Oledb,我在C#中使用axSpreadsheet控件,但设置源代码时出现错误 错误:无法将“System.Data.DataTable”强制转换为“msdatasrc.DataSource” 我的代码: string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filename + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'"; OleDbC

我在C#中使用axSpreadsheet控件,但设置源代码时出现错误

错误:无法将“System.Data.DataTable”强制转换为“msdatasrc.DataSource”

我的代码:

  string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filename + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
        OleDbConnection conn = new OleDbConnection(strConn);
        conn.Open();
        DataSet ds = new DataSet();
        OleDbDataAdapter odda = new OleDbDataAdapter("select * from [电子订单$]", conn);
        odda.Fill(ds, "table");
        axSpreadsheet1.DataSource = ds.Tables[0];
然后修改代码:
axSpreadsheet1.DataSource=ds.Tables[0]
to
axSpreadsheet1.DataSource=(msdatasrc.DataSource)ds.Tables[0],但仍然存在错误


我能做什么?

一个显而易见的解决方案是检查什么是
msdatasrc.DataSource
。创建一个新实例,然后逐行或使用其他工具将表中的行复制到该实例中。

有一个错误不是非常精确的问题描述,至少不允许我们提供帮助。hcemp-请阅读并修改您的问题