Private Sub Command1_Click()
Set hxc_record = New ADODB.Recordset
lssql = "select calling_nbr,called_nbr from extend_ticket where calling_nbr='" & Text1.Text & "'and calling_nbr>' '"
With hxc_record
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open lssql, conn
End With
Set DataGrid1.DataSource = hxc_record
End Sub执行完后datagrid是空的请问我该怎么办??
Set hxc_record = New ADODB.Recordset
lssql = "select calling_nbr,called_nbr from extend_ticket where calling_nbr='" & Text1.Text & "'and calling_nbr>' '"
With hxc_record
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open lssql, conn
End With
Set DataGrid1.DataSource = hxc_record
End Sub执行完后datagrid是空的请问我该怎么办??
你可以用adodc控件直接连
用一样的设置
工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)Option ExplicitDim WithEvents adoRS As Recordset
Dim db As Connection
'提数据事件
Set db = New Connection
db.CursorLocation = adUseClient
db.Open"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\db1.mdb;Jet OLEDB:Database Password=1234;"
' ##########################################
'打开密码是1234的Access2000数据库db1.mdb
'不需要密码,就把Jet OLEDB:Database Password=1234;这段去掉 Set adoRS = New Recordset
adoRS.Open "SELECT * FROM 表", db, adOpenStatic, adLockOptimistic
'赋值给 DataGrid 表
Set DataGrid1.DataSource = adoRS
'表刷新
DataGrid1.Refresh '如果要绑定TextBox(数组):
'Text1(0).DataField = 字段1
'Text1(1).DataField = 字段2
'.........
Dim oText As TextBox 'TextBox
For Each oText In Me.Text1
Set oText.DataSource = adoRS
Next
'添加事件和保存
adoRS.AddNew
'保存
adoRS![字段a] = text1.Text
adoRS![字段b] = text2.Text
adoRS.UpdateBatch adAffectAll'删除
adoRS.Delete
'重新赋值给表
adoRS.Requery
Set DataGrid1.DataSource = adoRS
DataGrid1.Refresh '其他相关操作:
'上一条
If Not adoRS.BOF Then adoRS.MovePrevious
If adoRS.BOF And adoRS.RecordCount > 0 Then
'已到最后返回
adoRS.MoveFirst
End If
'下一条
If Not adoRS.EOF Then adoRS.MoveNext '下一条
If adoRS.EOF And adoRS.RecordCount > 0 Then
'已到最后返回
adoRS.MoveLast
End If
'第一条
If Not adoRS.BOF Then adoRS.MoveFirst
'最末
If Not adoRS.EOF Then adoRS.MoveLast
Set hxc_record = New ADODB.Recordset
lssql = "select calling_nbr,called_nbr from extend_ticket where calling_nbr='" & trim(Text1.Text) & "'and calling_nbr>' '"With hxc_record
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source =lssql
.Open
End WithSet DataGrid1.DataSource = hxc_record
End Sub