我常用的写法,用Adodc控件,不用设置直接粘贴代码,因英语水平差,基本用中文写
Private Sub Form_Activate()
S = App.Path & "\LawStatute.mdb"
'数据库名称LawStatute,放在对应的编写程序夹内,为Access数据库
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =" + Chr(34) + S + Chr(34) & ";Jet OLEDB:Database Password=chen3523;"
'打开有密码数据库,密码为“chen3523”
Dim SQL As String
SQL = "SELECT * FROM 文件表 "
= adCmdunknow
'SQL必须用此句,否则会显示FROM子句出错
Adodc1.RecordSource = SQL
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
Private Sub Command1_Click()
Dim SQL As String
my = Chr(34) + "%" + Trim$(Text1.Text) + "%" + Chr(34)
SQL = "SELECT * FROM 文件表
where 文件名称 like " & my & " order by 发文时间 desc"
= adCmdunknow
'SQL必须用此句,否则会显示FROM子句出错
Adodc1.RecordSource = SQL
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub