希望你能帮助我. 我想通过使用某个关键字来过滤我的datagridview,例如名称. 我使用了一个数据集,然后将其绑定到数据源,然后绑定到我的datagridview进行查看. 当我使用bindingsource.filter时,我
我想通过使用某个关键字来过滤我的datagridview,例如名称.
我使用了一个数据集,然后将其绑定到数据源,然后绑定到我的datagridview进行查看.
当我使用bindingsource.filter时,我无法获得任何结果.
这是我的代码:
Dim ds As New DataSet Dim bs As New BindingSource Dim sql As String = "SELECT TOP 10 * FROM dbo.DimCustomer" Dim connection As New SqlConnection(sqlconnectionstring) Dim dataadapter As New SqlDataAdapter(sql, connection) connection.Open() ds.Clear() dataadapter.Fill(ds, "Customer") connection.Close() bs.DataSource = ds dgv1.DataSource = bs dgv1.DataMember = "Customer" bs.Filter = "FirstName = 'Jon'"谢谢大家的帮助,但我得到了以下代码:
Dim sql As String = "select * from HumanResources.vEmployee" Dim connection As New SqlConnection(sqlconnectionstring) Dim dataadapter As New SqlDataAdapter(sql, connection) Dim dsView As New DataView() Try connection.Open() ds.Clear() dataadapter.Fill(ds, "test") dsView = ds.Tables(0).DefaultView bs.DataSource = dsView dgv1.DataSource = bs bs.Filter = "FirstName like 'J%'" Catch ex As Exception MessageBox.Show("Error while connecting to SQL Server." & ex.Message) Finally connection.Close() End Try