如何使用文本框过滤数据网格 [英] How to filter datagrid using textbox
本文介绍了如何使用文本框过滤数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim connection As OleDb.OleDbConnection = New OleDbConnection
connection.ConnectionString =Provider = Microsoft.ACE.OLEDB.12.0; Data Source =& System.Environment.CurrentDirectory& \ InventSystem.accdb
connection.Open()
Dim da As OleDb.OleDbDataAdapter = New OleDbDataAdapter(SELECT * FROM Items WHERE Barcode Like'%& TextBox1.Text&% ',连接)
Dim ds As New DataTable
da.Fill(ds)
如果ds.Rows.Count = 0那么
MessageBox.Show(找不到记录 )
结束如果
connection.Dispose()
我试过的:
我真的很陌生。你能帮助我吗我觉得我的代码中缺少过滤datagrid
解决方案
我建议使用 Google [ ^ ]。
作为 Richard Deeming [ ^ ]提到您必须使用参数化查询( OleDbCommand [ ^ ]),例如:
Dim qry As String = SELECT * FROM Items WHERE Barcode Like'* @ find *';
注意:MS Access数据库引擎使用[*
]而不是[%
]。请参阅:类似运营商(Microsoft Access SQL) [Access 2007开发人员参考] [ ^ ]
Dim connection As OleDb.OleDbConnection = New OleDbConnection connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.Environment.CurrentDirectory & "\InventSystem.accdb" connection.Open() Dim da As OleDb.OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Items WHERE Barcode Like '%" & TextBox1.Text & "%' ", connection) Dim ds As New DataTable da.Fill(ds) If ds.Rows.Count = 0 Then MessageBox.Show("Record not Found") End If connection.Dispose()
What I have tried:
I'm really new to this. Can you guys help me i feel like there is missing on my code to filter the datagrid
解决方案
I'd suggest to use Google[^].
As Richard Deeming[^] mentioned you have to use parameterized query (OleDbCommand[^]), for example:
Dim qry As String = "SELECT * FROM Items WHERE Barcode Like '*@find*';"
Note: MS Access database engine is using [*
] instead of [%
]. Please see: Like Operator (Microsoft Access SQL) [Access 2007 Developer Reference][^]
这篇关于如何使用文本框过滤数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文