首页 > 解决方案 > Search multiple parameters in one search box

问题描述

So I have a asp net "site" that functions as a data input device. I added a search box to it to make it easier for people to find specific results in order to add data. My question is currently I have it so people search by the PONumber and it returns relevant data-rows. I just wanted to know if it was possible to keep the POnumber search but to also make it so people can search by classcodes as well within that same search box without making another one.

Like I mentioned I have a working version that does what I want it to do and I'm happy with it for the most part. Just looking at options.

 Private Sub SearchVen()
       Dim Constr As String = ConfigurationManager.ConnectionStrings("PurchaseOrderConnectionString").ConnectionString
       Using Con As New SqlConnection(Constr)
           Using cmd As New SqlCommand
               Dim searchword As String = "SELECT PurchaseOrder.PoId, PurchaseOrder.Vendor_Name, PurchaseOrder.POAmount,PurchaseOrder.DateFrom, PurchaseOrder.DateTo, PurchaseOrder.Balance, PurchaseOrder.CodeId, PurchaseOrder.PoNumber, BPNumber, ClassCode.CodeId AS Expr1, ClassCode.CodeDefinition, PurchaseOrder.Notes FROM PurchaseOrder INNER JOIN ClassCode ON PurchaseOrder.CodeId = ClassCode.CodeId"
               If Not String.IsNullOrEmpty(TextBox11.Text.Trim()) Then
                   searchword += " Where PurchaseOrder.PONumber Like @POnumber + '%'"
                   cmd.Parameters.AddWithValue("PONumber", TextBox11.Text.Trim())
               End If
               cmd.CommandText = searchword
               cmd.Connection = Connection
               Using sda As New SqlDataAdapter(cmd)
                   Dim dt As New DataTable()
                   sda.Fill(dt)
                   GridView1.DataSourceID = ""
                   GridView1.DataSource = dt
                   GridView1.DataBind()
               End Using
           End Using
       End Using
   End Sub

Edit1:

                Dim searchword As String = "SELECT PurchaseOrder.PoId, PurchaseOrder.Vendor_Name, PurchaseOrder.POAmount,PurchaseOrder.DateFrom, PurchaseOrder.DateTo, PurchaseOrder.Balance, PurchaseOrder.CodeId, PurchaseOrder.PoNumber, BPNumber, ClassCode.CodeId AS Expr1, ClassCode.CodeDefinition, PurchaseOrder.Notes FROM PurchaseOrder INNER JOIN ClassCode ON PurchaseOrder.CodeId = ClassCode.CodeId"
                If Not String.IsNullOrEmpty(TextBox11.Text.Trim()) Then
                    searchword += " Where PurchaseOrder.PONumber Like @POnumber + '%'" Or "ClassCode.CodeDefinition like @CodeDefinition + '%'"
                    cmd.Parameters.AddWithValue("PONumber", TextBox11.Text.Trim())
                    cmd.Parameters.AddWithValue("CodeDefinition", TextBox11.Text.Trim())
                End If

Tried putting this in and get a input string is in incorrect format error message.

标签: asp.netvb.net

解决方案


推荐阅读