使用 axSpreadsheet 控件设置源时出现转换错误

发布于 2024-09-17 17:11:49 字数 777 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是暖光i 2024-09-24 17:11:49

一个明显的解决方案是检查什么是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文