其实这里涉及用SQL查询的问题。最好还是找书看看,因为我年纪比较大,看了很久才懂一点点。如果我把语句写上,到你的程序未必可以使用,因为不知你数据库的字段结构。
我用的是Adocd控件查询,以下是我程序用的语句,目前使用查询的人说还可以好用:
If DataCombo1.Text = "点击选择项目名称" Or DataCombo1.Text = "" Then
My = ""
Else
My = "项目名称=" & Chr(34) + DataCombo1.Text + Chr(34)
End If
If Text1.Text = "输入关键词" Or Text1.Text = "" Then
You = ""
Else
You = Chr(34) + "%" + Trim$(Text1.Text) + "%" + Chr(34)
End If
If My = "" And You = "" Then
SQL = "SELECT * FROM 项目文件表
order by 文件ID desc"
ElseIf My <> "" And You <> "" Then
SQL = "SELECT * FROM 项目文件表
where
" & My & " and 文件名 like " & You & " order by 文件ID desc"
ElseIf My = "" And You <> "" Then
SQL = "SELECT * FROM 项目文件表
where
文件名 like " & You & " order by 文件ID desc"
ElseIf My <> "" And You = "" Then
SQL = "SELECT * FROM 项目文件表
where
" & My & " order by 文件ID desc"
End If
= adCmdunknow
Adodc1.RecordSource = SQL
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Width = 0
DataGrid1.Columns(2).Width = DataGrid1.Width - DataGrid1.Columns(1).Width - DataGrid1.Columns(3).Width - DataGrid1.Columns(4).Width - DataGrid1.Columns(5).Width - DataGrid1.Columns(6).Width - 300
[
本帖最后由 chen3523 于 2014-10-6 21:55 编辑 ]