因此,我有一个充当数据输入设备的asp网“站点”。我在其中添加了一个搜索框,以便人们更轻松地找到特定结果以添加数据。我的问题是我现在有它,因此人们可以按PONumber进行搜索,并返回相关的数据行。我只是想知道是否可以保留POnumber搜索,但同时也可以这样做,以便人们也可以在同一搜索框中通过类代码进行搜索,而无需再进行搜索。
就像我提到的那样,我有一个工作版本可以满足我的要求,并且我对此感到非常满意。只看选项。
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
尝试将其放入并获得输入字符串的格式错误消息。