'没有为一个或多个必需参数给出值.'错误,无法克服 [英] 'No value given for one or more required parameters.' Error, Can't get over it
问题描述
我正在尝试从我的 Access 数据库中获取一个是/否值,并使其如此,如果在 Access 上选中是/否,它将在表单上进行检查.虽然我不断得到
I'm trying to take a Yes/No value from my database on Access and make it so if the Yes/No is checked on Access it will check it on the form. Although I keep getting
System.Data.OleDb.OleDbException: '没有为一个或多个必需参数提供值.'
System.Data.OleDb.OleDbException: 'No value given for one or more required parameters.'
在线Dim rs As OleDbDataReader = SQLCmd.ExecuteReader()
对不起,如果这是一个非常简单和愚蠢的错误,我是一名大学生,谷歌搜索并不能帮助我解决这个问题.
Sorry if it's a really easy and stupid mistake, I'm a college student and googling isn't helping me figure this one out.
cn.Open()
Dim SQLCmd As New OleDbCommand
SQLCmd.Connection = cn
SQLCmd.CommandText = "SELECT *, staffIn FROM Staff WHERE staffName = DarrenSloan"
Dim rs As OleDbDataReader = SQLCmd.ExecuteReader()
While rs.Read
Dim DisplayValue As String = rs("staffIn")
SQLCmd.Parameters.AddWithValue("@inorout", inOrOut.Checked)
SQLCmd.ExecuteNonQuery()
End While
cn.Close()
推荐答案
我知道 this 是一个旧帖子,但我好像记得OleDb不支持命名参数.
I know this is an old post but I seem to remember that OleDb does not support named parameters.
另外,很确定 DarrenSloan
应该用单引号括起来,就像任何字符串值一样.确实,像这样重用 SQL 命令并不是解决问题的方法.
Also, pretty sure that DarrenSloan
should be surrounded by single quotes, like any string value. And indeed, reusing the SQL command like this is not the way to do it.
命令文本:
SQLCmd.CommandText = "SELECT *, staffIn FROM Staff WHERE staffName = DarrenSloan"
不包含任何参数.因此,参数 inorout
无效:
does not contain any parameter.
Thus, the parameter inorout
has no effect:
SQLCmd.Parameters.AddWithValue("@inorout", inOrOut.Checked)
使用两条语句,一条 SELECT 和一条 UPDATE.或者使用不同的机制,如数据绑定网格.也许您正在使用 datagridview
控件来显示数据.然后有不同的技术来保持数据同步.这取决于您选择如何在表单上呈现数据.
Either use two statements, one SELECT and one UPDATE.
Or use a different mechanism like a databound grid. Maybe you are using a datagridview
control to display the data. Then there are different techniques to keep the data in sync. It depends on how you choose to render the data on your form.
这篇关于'没有为一个或多个必需参数给出值.'错误,无法克服的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!