VB visual studio中执行阅读器的问题

编程入门 行业动态 更新时间:2024-10-26 12:28:39
本文介绍了VB visual studio中执行阅读器的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我运行以下代码时,在声明数据读取器博士时出现错误

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中执行阅读器的问题

本文发布于:2023-11-11 21:10:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阅读器   VB   visual   studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!