[英]VB.NET Search with TextBox and DataGridView
From TextBox I search in DataGridView based on (Id), (DateTimePichKer), (Text column), and 5 Columns that have numbers.从 TextBox 中,我根据 (Id)、(DateTimePichKer)、(Text 列) 和 5 个具有数字的列在 DataGridView 中进行搜索。 When I search for 1 or more numbers, it gives me the result in line, that is, I ask (20, 30, 40) it only gives me the sequence as I wrote it while I would like the 3 numbers to be found also in different positions, such as: (30,20,40) or (40,30, 20 ) and so on, how can I do?当我搜索 1 个或多个数字时,它会给我一行结果,也就是说,我问 (20, 30, 40) 它只给了我写它的序列,而我也希望找到这 3 个数字在不同的位置,例如: (30,20,40) 或 (40,30, 20 ) 等等,我该怎么办?
Solved Partially, up to 2 numbers works from the third (with 3 or 4 or 5 numbers) onwards no, it gives me the blank row with no data.部分解决,从第三个(有 3 个或 4 个或 5 个数字)开始,最多 2 个数字有效,不,它给了我没有数据的空白行。
Public Sub FilterData(ValueToSearch As String)
Try
Dim SearchQyery As String = "SELECT * FROM LottoDeaBendata WHERE CONCAT_WS([Estratto1],[Estratto2],[Estratto3],[Estratto4],[Estratto5])LIKE'%" & ValueToSearch & "%'"
Dim command As New SqlCommand(SearchQyery, connection)
connection.Open()
Dim table As New DataTable()
Dim adapter As New SqlDataAdapter(command)
adapter.Fill(table)
DataGridView1.DataSource = table
connection.Close()
Catch ex As Exception
MsgBox(ex.Message) 'show error msg'
End Try
End Sub
Private Sub btnFiltraDati_Click(sender As Object, e As EventArgs) Handles btnFiltraDati.Click
FilterData(txtRefreshFiltra.Text)
End Sub
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
Try
If e.ColumnIndex = 3 And e.Value IsNot Nothing Or e.ColumnIndex = 4 And e.Value IsNot Nothing Or e.ColumnIndex = 5 And e.Value IsNot Nothing Or e.ColumnIndex = 6 And e.Value IsNot Nothing Or e.ColumnIndex = 7 And e.Value IsNot Nothing Then
If String.IsNullOrEmpty(txtRefreshFiltra.Text) Then
txtRefreshFiltra.Text = ""
End If
Dim sum6 As String = Convert.ToInt32(e.Value)
If sum6 = txtRefreshFiltra.Text Then
e.CellStyle.BackColor = Color.Gold
e.CellStyle.ForeColor = Color.Black
End If
End If
Catch ex As Exception MsgBox(ex.Message) 'show error msg' End Try End Sub Catch ex As Exception MsgBox(ex.Message) 'show error msg' End Try End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.