OleDbException:当未定义任何参数时,没有为参数提供任何值 [英] OleDbException: no value given for parameters when no parameters are defined
问题描述
在正在开发的应用程序上运行测试时遇到OleDbException.给出的错误消息是,没有为一个或多个必需参数提供值."
I'm encountering an OleDbException whilst running tests on an application I'm developing. The error message given is, 'No value given for one or more required parameters.'
我知道这个问题在此站点上似乎已经被问过几次了,但是在每种情况下,执行UPDATE
命令时都会出现问题.我的错误被抛出在我的SELECT
命令中;更令人困惑的是,我什至没有尝试使用参数,所以我不确定它期望使用什么参数.引发异常的方法的代码如下:
I know this question appears to have been asked several other times on this site, but in each of the cases the problem arises whilst executing an UPDATE
command. My errors are being thrown in my SELECT
command; to add to the confusion, I'm not even trying to use parameters, so I'm not sure what parameters it's expecting. Code for the method which raises the exception is below:
// Array of column letters, used in constructing the select query.
private readonly string[] COLUMN_LABELS = new string[] { "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ", "BA", "BB",
"BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL",
"BM", "BN", "BO", "BP", "BQ", "BR", "BS", "BT", "BU", "BV",
"BW", "BX", "BY", "BZ" };
public AvailabilityReader(string spreadsheet, List<ServiceType> sundayList)
{
// Set up a connection to the spreadsheet.
this.spreadsheet = spreadsheet;
Connection = new OleDbConnection(string.Format((Spreadsheet.EndsWith(".xlsx") ?
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=Excel 12.0;" :
"Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;"), Spreadsheet));
// Set up an adapter for the spreadsheet.
ColumnNames = new List<string>();
var columnString = "[E-mail Address] AS Email";
for (int i = 1; i <= sundayList.Count; i++)
{
columnString += string.Format(", Column{0}", i);
ColumnNames.Add(string.Format("Column{0}", i));
}
var selectCommand = new OleDbCommand(string.Format("SELECT {0} FROM [DATA$O5:{1}300]", columnString, COLUMN_LABELS[sundayList.Count - 1]), Connection);
Adapter = new OleDbDataAdapter(selectCommand);
CommandBuilder = new OleDbCommandBuilder(Adapter);
CommandBuilder.QuotePrefix = "[";
CommandBuilder.QuoteSuffix = "]";
// Obtain the table.
var data = new DataSet();
Adapter.Fill(data, "DATA");
table = data.Tables["DATA"];
}
调用Adapter.Fill(data, "DATA")
时会引发异常(适配器是AvailabilityReader
类的私有属性).
The exception is raised when Adapter.Fill(data, "DATA")
is called (Adapter being a private property of the AvailabilityReader
class).
老实说,我不知道发生了什么,但是我完全希望错过一些非常简单的事情.预先感谢!
I honestly have no idea what's going on, but I fully expect to have missed something incredibly simple. Thanks in advance!
推荐答案
通常在您的列名不正确时发生.确保它们与您要从中获取数据的表一致.
This usually occurs when your column names are incorrect. Make sure they are consistent with the table you are getting the data from.
这篇关于OleDbException:当未定义任何参数时,没有为参数提供任何值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!