左顾右盼顾是什么意思:vb select语句

来源:百度文库 编辑:中科新闻网 时间:2024/05/08 22:55:51
使用MSHFlexGrid控件
查询一个数据时
Private DataRct As New ADODB.Recordset
Private Sub cmdFind_Click()
DataRct.Open "select * from orders where OrderID='" & txtName.Text & "'", Cnn, adOpenKeyset, adLockOptimistic, -1
Set MsfGrd.DataSource = DataRct
DataRct.Close
End Sub
没问题,能显示出来
可我想查全部数据时
DataRct.Open "select * from orders, Cnn, adOpenKeyset, adLockOptimistic, -1
却报错误:连接无法用与执行此操作.在此上下问中他可能已被关闭或无效.
我只改了一下Select语句,别的什么都没动,为什么会出现这种错误呢?
模块里写了
Public Cnn As New ADODB.Connection
Sub main()
If cc = True Then
Form1.Show
MsgBox "成功"
Else
MsgBox "数据库连接失败", vbExclamation + vbOKOnly, "失败"
End
End If
End Sub
Function cc() As Boolean
On Error GoTo err
Cnn.ConnectionString = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=."
Cnn.Open
cc = True
Exit Function
err:
cc = False
End Function

"select * from orders", Cnn, adOpenKeyset, adLockOptimistic, -1

你忘了个 " ,肯定出错