我是编程新手,我在 VB.net 中编写的 Web 应用程序有问题。我的项目中有一个 Access 数据库,并且正在使用参数化查询从中检索信息。奇怪的是,我在另一个工作正常的页面上使用了几乎相同的查询,但是这个查询给了我“没有为一个或多个必需参数提供值”错误。我一天中的大部分时间都在搜索,并意识到问题已被提出,但找不到我的问题的解决方案。我想我正在使用“?” 正确,以正确的顺序具有正确数量的参数,并且所有内容都拼写正确。这是我的代码:
Dim strWthStn As String
strWthStn = cboRainProb2.Text
Dim strWthStnParm As New OleDb.OleDbParameter()
strWthStnParm.Value = strWthStn
Dim strMonth As String
strMonth = cboRainProb.Text
Dim strMonthParm As New OleDb.OleDbParameter()
strMonthParm.Value = strMonth
Dim sql As String 'Query to select the station for rainfall probability values
sql = "SELECT 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 " &
"FROM Rainfall Probability " &
"WHERE Station = ?" &
"AND Mth = ?"
'Connects to the Access database and selects data based on query
Dim AccessConnect As String
AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Megan\Visual Studio Projects\DroughtCalculatorND_Web\DroughtCalculatorND_Web\NDStations.mdb"
Dim conn As New OleDb.OleDbConnection
Dim selectCommand As New OleDbCommand(sql, conn)
selectCommand.Parameters.Add(strWthStnParm)
selectCommand.Parameters.Add(strMonthParm)
conn.ConnectionString = AccessConnect
conn.Open()
'Reads the data into a list
Dim reader As OleDbDataReader =
selectCommand.ExecuteReader(CommandBehavior.CloseConnection)
Dim RainByYear As New List(Of Double)
reader.Read()
RainByYear.Add(reader("1999"))
RainByYear.Add(reader("2000"))
RainByYear.Add(reader("2001"))
RainByYear.Add(reader("2002"))
RainByYear.Add(reader("2003"))
RainByYear.Add(reader("2004"))
RainByYear.Add(reader("2005"))
RainByYear.Add(reader("2006"))
RainByYear.Add(reader("2007"))
RainByYear.Add(reader("2008"))
RainByYear.Add(reader("2009"))
RainByYear.Add(reader("2010"))
RainByYear.Sort()
等等
在 OleDBDataReader 行的 Dim 阅读器上出现程序错误。我在那里使用了一个断点来检查所有内容,并且两个参数都有正确的值。我感谢任何帮助,谢谢。