【发布时间】:2018-03-26 01:21:35
【问题描述】:
我已经开始创建一个应用程序,它最终可以让某人选择多个年份组并整理电子邮件地址列表。
到目前为止,我已将一个 excel 文件导入到 dataGridView 框中并设法过滤掉项目,例如,我过滤了“第 7 年”。一旦我选择“第 8 年”,之前的搜索就会消失。有时我需要同时选择 7 年级、8 年级和 9 年级。
这是我目前所拥有的。
最初我认为我可以创建一个 if 语句,但它似乎只是搜索语句中的最后一件事。
Public Class Form1
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim dataSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim path As String = "C:\Users\Lenovo\Desktop\Username finder\data.xlsx"
Dim dv As DataView
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [usernames$]", MyConnection)
dataSet = New System.Data.DataSet
MyCommand.Fill(dataSet)
DataGridView1.DataSource = dataSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
Private Sub CheckBoxY7_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBoxY7.CheckedChanged
' dv = New DataView(dataSet.Tables(0), "Year = '7' ", "Surname Desc", DataViewRowState.CurrentRows)
' DataGridView1.DataSource = dv
End Sub
Private Sub CheckBoxY8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBoxY8.CheckedChanged
' dv = New DataView(dataSet.Tables(0), "Year = '8' ", "Surname Desc", DataViewRowState.CurrentRows)
' DataGridView1.DataSource = dv
End Sub
【问题讨论】:
标签: vb.net search checkbox import datagrid