语句没有错,查询返回记录不正确。

高原山顶的大风车 2008-09-04 02:58:41

今天偶尔发现的,不知道原因,代码也是别人写的。


Set rst = New ADODB.Recordset

''如果是静态打开(在客户端内存中生成副本则将游标类型设置为客户端游标)

If cursorType = adOpenStatic Then
rst.CursorLocation = adUseClient
End If

cn.Close
SQL = "Select * from Card where CardID=4"'''cardid是主键、自增长标识,现在card表中有几十条记录。
cn.ConnectionString = "...."
cn.Open
rst.Open Trim$(SQL), cn, cursorType, adLockOptimistic

msgstring = "查询到" & rst.RecordCount & " 条记录"


现在出现的情况是:
SQL = "Select * from Card where CardID=4" 时rst.RecordCount =1 CardID=8的记录存在card表中
SQL = "Select * from Card where CardID=8" 时rst.RecordCount =0 CardID=8的记录存在card表中
SQL = "Select * from Card" 时rst.RecordCount =3  card表中有几十条记录

不知道是什么原因?

...全文
64 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
cn.ConnectionString = "...."

 写的是固定连接,在多次尝试中不会发生改变。
wxg22526451 2008-09-04
  • 打赏
  • 举报
回复
SQL没错。。
检查连接字符串
子陌红尘 2008-09-04
  • 打赏
  • 举报
回复
连错数据库了吧??

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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