使用 axSpreadsheet 控件设置源时出现转换错误
我在 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];
到 axSpreadsheet1 .DataSource = (msdatasrc.DataSource)ds.Tables[0];
,仍然有错误。
我能做些什么?
I use the axSpreadsheet control in C#, but when I set the source there's an error.
error: can not cast "System.Data.DataTable" to "msdatasrc.DataSource"
My Code:
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];
Then I modify the code: axSpreadsheet1.DataSource = ds.Tables[0];
to axSpreadsheet1.DataSource = (msdatasrc.DataSource)ds.Tables[0];
, and still have the error.
What can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个明显的解决方案是检查什么是
msdatasrc.DataSource
。创建它的一个新实例,然后将表行逐行或使用其他工具复制到其中。One obvious solution is to examine what is
msdatasrc.DataSource
. Create a new instance of it and than copy over the table rows to it, row by row or by using some other tool.