帮助搜索功能 [英] Help with a search function
问题描述
我一直试图解决这个问题。我目前正在尝试编写一些代码,它将搜索我的数据库以获得答案,它将检查答案并返回布尔输出(True或False)。我已经走到了这一步,但是当我使用
代码时,我得到它说 'System.Data.OleDb.OleDbException:'没有给出一个或多个必需参数的值。' 这个
告诉我搜索的代码不起作用,如果有人可以帮助我,我将非常感激。
I have been trying for a while to solve this problem. I am currently trying to write some code, which will search my database for an answer, it will check the answer and will return a Boolean output (True or False). I have got this far, but when using the code I was given it says 'System.Data.OleDb.OleDbException: 'No value given for one or more required parameters.' This shows me that the code for the search is not working, if anyone could help me it would be much appreciated.
Private Sub Login_button_click(sender As Object, e As EventArgs) Handles Login_Button.Click
If Not String.IsNullOrEmpty(Password_Box.Text) Then
Dim dt As New DataTable
Dim commandtext As String = "select answer from infotmation where username=@username and password=@password"
Using cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\bobby\Documents\DOFE App\Starting_App Access Database\Database.accdb;")
Using cmd As New OleDbCommand(commandtext, cn)
cmd.Parameters.AddWithValue("@username", Username_Box.Text)
cmd.Parameters.AddWithValue("@password", Password_Box.Text)
cn.Open()
dt.Load(cmd.ExecuteReader())
End Using
End Using
Else
MessageBox.Show("Please supply some text for the search")
End If
End Sub
推荐答案
试试下一个命令:
Try the next command:
Dim commandtext As String = "select answer from infotmation where username=? and password=?"
这篇关于帮助搜索功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!