我的代码如下,运行不成功,提示缺少函数或变量,恳求指教!
Private Sub Command1_Click()
Dim strSql As String
If Text1.Text <> "" Then
Adodc1.Recordset.Close
If Val(Text1.Text) > 0 Then
strSql = "select * from xsxx where XH =" & Trim(Text1.Text)
Else
strSql = "select * from xsxx where XM='" & Trim(Text1.Text) & "'"
End If
Adodc1.CommandType = adCmdText
Adodc1.Recordset.Open = strSql
Set DateGrid1.DataSource = Adodc1
Else
Set DateGrid1.DataSource = Nothing
End If
End Sub
DateGrid1?似乎这是VB的玩法吧?在Access里,应该记录集和数据连接吧?
Dim Adodc1 As New ADODB.Connection
Dim Cmd As ADODB.Command
…………………………
Cmd.CommandText=strSql
Set Adoc1=CurrentProject.Connection
Adodc1.Execute strSql
…………………………
VB中用OpenDatabase和OpenRecordset方法就可以打开数据库或者记录集了。例如:
Dim Db As Database
Set Db=OpenDatabase("C:\XXX.mdb")
db.Execute ssql
DataGird1.RecordSource=ssql2
………………………………