简体   繁体   English

在C#中打开Excel文件

[英]Opening an Excel file in c#

So there are a lot of questions regarding this method on SO, but none seem to answer my question. 因此,关于此方法在SO上存在很多问题,但似乎没有一个问题可以回答我的问题。 I firstly had an issue with the connectionstring (although it seems to work in other areas of my code correctly). 我首先遇到了连接字符串的问题(尽管它似乎可以在我的代码的其他区域正常工作)。 This was resolved easily. 这很容易解决。

Now the issue is with a simple SELECT query via a OLEDBCommand (Text) that keeps popping up the following error? 现在的问题是通过OLEDBCommand(文本)进行的简单SELECT查询,该查询不断弹出以下错误?

"SELECT [Opportunity#],[BidManager],[Prob %],[Opportunity_Stage].[Opportunity_Status],[Term],[Sign Date] FROM [Sheet1$];"

No value given for one or more required parameters.

but their are no parameters???? 但他们没有参数????

Checked and double checked the columns names, but to no avail. 检查并再次检查列名称,但无济于事。 Also tried removing the special characters from the column names, but still the same exception. 还尝试从列名称中删除特殊字符,但仍然是相同的例外。

I'd suggest trying to run SELECT * FROM [Sheet1$] that way you'll know pretty certain if it's a column issue or an issue with the rest of the code. 我建议尝试以这种方式运行SELECT * FROM [Sheet1$] ,这样您就可以确定是列问题还是其余代码问题。 Also, I can't check at the very moment, but are you sure there should be a ; 另外,我目前无法核对,但您确定应该有一个; after the select statement, isn't that just when you want to execute multiple statements? 在select语句之后,这不只是在您要执行多个语句时吗?

OleDbCommand requires two parameters, the command string you are trying to execute and the OleDbConnection itself. OleDbCommand需要两个参数,您要执行的命令字符串和OleDbConnection本身。 Are you calling it correctly? 您打的正确吗?

Dim myConnection As New OleDbConnection(myConnString)
OleDbCommand myCommand = new OleDbCommand(mySelectQuery,myConnection);

I've had this error with an OleDb command when my column names were incorrect. 当我的列名不正确时,我在OleDb命令中遇到了此错误。

"No value given for one or more required parameters." “没有为一个或多个必需参数提供值。”

I assume that the database interprets any columns names that it cannot find as parameters 我假设数据库会将无法找到的任何列名称解释为参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM