本文介绍了选择带有多个LIKE的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户输入文本到文本框A中。

功能
在数据库记录中搜索与用户输入相对应的名字和姓氏。



问题:



看来我得到的结果只是搜索名字字段而不是名字和姓氏字段

示例:



* 搜索Mike会返回: * p>

Mike Smith



Mike Jones

搜索Jones:



Mike Jones未被退回



  Protected Sub button1_Click(ByVal sender As Object,ByVal e As EventArgs) Handles button1.Click 

If txtSearch.Text =Then

Else

Dim ConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings( oakfratintdbConnectionString)。ConnectionString
Dim Conn As New SqlConnecti (SELECT [FirstName],[LastName],[MidInitName],[NameSuffix],[NamePrefix],[DOB],[DOD],[BurialDate],[GeoDirection ([FirstName] LIKE @FirstName),Conn)
Dim searchDT As DataTable = GetData(searchCMD) )
GridView1.DataSource = searchDT
GridView1.DataBind()
End If

End Sub

$ b

代码解释:

txtSearch是用户的搜索输入

解决方案

更改

  SELECT [FirstName], [LastName],[MidInitName],[NameSuffix],[NamePrefix],[DOB],
[DOD],[BurialDate],[GeoDirection],[Space],[Lot],[Row] ],
[AddtlInfo] FROM [OFCInterments] WHERE([FirstName] LIKE @FirstName)

  SELECT [Fir [姓名],[姓名],[姓名],[出生年],[$] ,[IntermentSpec],
[AddtlInfo] FROM [OFCInterments] WHERE([FirstName] LIKE @FirstName或
LastName like @LastName)


Functionality

User inputs text into textboxA.Search the database records for First Names AND Last Names corresponding to the user's input.

The Problem:

It appears the results I am getting are only searching "First Name" field and not BOTH the First Name and Last Name Fields

Example:

*A search for "Mike" returns:*

Mike Smith

Mike Jones

A search for "Jones":

Mike Jones is not returned

CODE:

Protected Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click

    If txtSearch.Text = "" Then

    Else

        Dim ConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("oakfratintdbConnectionString").ConnectionString
        Dim Conn As New SqlConnection(ConnString)
        Dim searchCMD As New SqlCommand("SELECT [FirstName], [LastName], [MidInitName], [NameSuffix], [NamePrefix], [DOB], [DOD], [BurialDate], [GeoDirection], [Space], [Lot], [Row], [IntermentSpec], [AddtlInfo] FROM [OFCInterments] WHERE ([FirstName] LIKE @FirstName)", Conn)
        Dim searchDT As DataTable = GetData(searchCMD)
        GridView1.DataSource = searchDT
        GridView1.DataBind()
    End If

End Sub

Code Explanation:

txtSearch is the user's search input

解决方案

Change

SELECT [FirstName], [LastName], [MidInitName], [NameSuffix], [NamePrefix], [DOB], 
[DOD], [BurialDate], [GeoDirection], [Space], [Lot], [Row], [IntermentSpec], 
[AddtlInfo] FROM [OFCInterments] WHERE ([FirstName] LIKE @FirstName)

to

SELECT [FirstName], [LastName], [MidInitName], [NameSuffix], [NamePrefix], [DOB], 
[DOD], [BurialDate], [GeoDirection], [Space], [Lot], [Row], [IntermentSpec], 
[AddtlInfo] FROM [OFCInterments] WHERE ([FirstName] LIKE @FirstName or 
LastName like @LastName)

这篇关于选择带有多个LIKE的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 07:10