为什么这段程序无效?(vb数据库)

minwellmax 2002-06-23 08:27:24
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
cn.Close
End
End Sub
Private Sub Form_Load()
cn.Provider = "SQLOLEDB.1"
cn.Properties("Persist Security Info").Value = "False"
cn.Properties("User ID").Value = "sa"
cn.Properties("Initial Catalog").Value = "pubs"
cn.Properties("Data Source").Value = "192.168.0.247"
'cn.Properties("Integrated Security").Value = "SSPI"
'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Northwind;Data Source=192.168.0.247
cn.Open
Set rs.ActiveConnection = cn
rs.Source = "Products"
rs.CursorType = adOpenForwardOnly
rs.LockType = adLockReadOnly
rs.Source = "select * from products"
rs.Open
If rs.RecordCount > 0 Then
Set DataGrid1.DataSource = rs
End If
End Sub
...全文
89 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dude 2002-07-08
  • 打赏
  • 举报
回复
aa
minwellmax 2002-06-25
  • 打赏
  • 举报
回复
那时注释啊,我的目的是想问rs.open()括号里边的参数就算全填了也会说缺少等于表达式的。不信你试rs.open()按照它的提示去填参数。
topikachu 2002-06-24
  • 打赏
  • 举报
回复
开什么玩笑!
要么将cn.Properties("Initial Catalog").Value = "pubs"改为Northwind
要么将sql语句写成rs.Source = "select * from Northwind.dbo.products"
还有
rs.CursorType = adOpenStatic或者rs.CursorType = adOpenKeyset
你的代码怎么那么麻烦阿!
mazhayang 2002-06-24
  • 打赏
  • 举报
回复
你上面为什么设定了两个rs.source
atq9 2002-06-24
  • 打赏
  • 举报
回复
你的格式有问题。没有括号
minwellmax 2002-06-23
  • 打赏
  • 举报
回复
可以的,我把rs.Source = "select * from products"改为rs.open "select * from products就可以了,但是为什么写成rs.open("select * from products")却不可以呢?不知道
gaodz 2002-06-23
  • 打赏
  • 举报
回复
DataSource可以连接rs记录集吗?我印象里是不可以的

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧