在使用vb.net的ms访问查询中需要帮助 [英] Need help in ms access query using vb.net
本文介绍了在使用vb.net的ms访问查询中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在程序中遇到麻烦,我想搜索数据库,如果它在我输入的字符串上有单词/短语.如果在那里,它将通过消息框显示,否则提示没有.我在查询中尝试使用LIKE,但它仅搜索包含我键入的字符串的数据库.我希望它是相反的...
这是我的代码,我知道它的可怕,请帮忙.
Hi guys,
i am having trouble in my program , i want to search the database if it has the word/phrase on the string i typed in. if it was there it will be shown through messagebox else prompt that there isnt. i tried using LIKE in my query but it only search the database that contains the string i typed. i want it to be the opposite...
this is my code i know its horrible please help.
Public Sub searchSpecial(ByVal UserInput)
conn.ConnectionString = c_string_special
conn.Close()
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
With cmd
.Connection = conn
.CommandText = "SELECT * FROM fear WHERE sentence LIKE '% %'"
.CommandType = CommandType.Text
dr = .ExecuteReader
End With
If dr.Read() Then
Dim x = dr.Item("sentence")
If x.ToString.Contains(UserInput) Or UserInput.ToString.Contains(x) Then
MsgBox(UserInput)
End If
End If
conn.Close()
End Sub
推荐答案
您正在搜索句子字段中包含空格的每一行.
您应该搜索类似这样的内容:
.CommandText =从恐惧中选择的句子,而在句子中则类似于"%". UserInput&%""
You are searching for every row in which the sentence fields has something with one space.
You should search for something, like this :
.CommandText = "SELECT sentence FROM fear WHERE sentence LIKE ''%"& UserInput &"%''"
这篇关于在使用vb.net的ms访问查询中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文