嗨
当我运行以下代码时,在声明数据读取器博士时出现错误
when I run the following code I get an error where I declare dr the data reader
在行'dr = cmd.ExecuteReader()'上出现以下错误:
on line 'dr = cmd.ExecuteReader()' I am getting the following error:
System.Data.OleDb.OleDbException:'未为一个或多个必需参数提供值.'
System.Data.OleDb.OleDbException: 'No value given for one or more required parameters.'
只是想知道是否有人知道如何解决这个问题?
just wondering if anyone knows how to solve this?
Private Sub carFinder(b As String, m As String, s As String, d As String, e As String) myConnection.ConnectionString = My.Forms.Main.connString myConnection.Open() Dim match As String match = "SELECT * FROM CxDetails WHERE (CBrand = '" & b & "' and CModel = '" & m & "' and CSpec ='" & s & "'and CNoOfDoors = '" & d & "' and CEngineSize ='" & e & "')" Dim cmd As OleDbCommand = New OleDbCommand(match, myConnection) dr = cmd.ExecuteReader() myConnection.Close() Dim CO2e As String = dr("CCO2") Dim COTR As String = dr("COTR")
推荐答案
我看不到问题,但是从今天的VB开始使用了更多内容,我在该样式,当然未经测试,我没有您的数据库.
I don't see the problem, but use a little bit more from todays VB, I changed your code in that style, of course not tested, I don't have your database. Private Sub carFinder(b As String, m As String, s As String, d As String, e As String) Dim CO2e As String Using myConnection.ConnectionString = My.Forms.Main.connString myConnection.Open() Dim match As String match = "SELECT * FROM CxDetails WHERE (CBrand = @b and CModel = @m and CSpec = @s and CNoOfDoors = @d and CEngineSize = @e)" Using cmd As New OleDb.OleDbCommand(match, myConnection) cmd.Parameters.AddWithValue("@b", b) cmd.Parameters.AddWithValue("@m", m) cmd.Parameters.AddWithValue("@s", s) cmd.Parameters.AddWithValue("@d", d) cmd.Parameters.AddWithValue("@e", e) Dim dr = cmd.ExecuteReader() While dr.Read CO2e = dr("CC2E") 'be aware this is case sensitive 'The rest End While End Using End Using End Sub
因此,请注意上面的代码中的typeos和小错误.
Therefore watch typeos and small mistakes in the code above.
更多推荐
VB visual studio中执行阅读器的问题
发布评论