| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 210 人关注过本帖
标题:(查错)请版主来帮个忙
收藏  订阅  推荐  打印
jxawgyl
Rank: 3Rank: 3
等级:中级会员
帖子:165
积分:2160
注册:2007-10-16
(查错)请版主来帮个忙

sql语句:
Private Sub Command1_Click()
'创建Connection对象cnn,关键New用于创建新对象
  Dim cnn As New ADODB.Connection
  '创建Recordset对象rs1
  Dim rs1 As New ADODB.Recordset
  Dim rs2 As New ADODB.Recordset
  
  '设置连接字符串ConnectionString属性
  cnn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=jchisn;Data Source=JXJXYY"
  '打开到数据库的连接
  cnn.Open
  Dim sql As String
  Dim sum As String

  sql = "select offname as 科室,hoscode as 住院号,patname as 病人姓名,medname As 药品名称, medspec As 规格, roomunit As 单位, roomprice As 单价, number As 数量, selfallmoney As 金额, sendopecode As 发药人, exectime As 发药时间 from AdviceListView where roomcode=2000 and sendopecode>0 " & _
           "and hoscode like '" & Text1.Text & "%" & "' " & _
           " and offname like'" & Combo1.Text & "%" & "' " & _
           " and medname like'" & Text2.Text & "%" & "' " & _
           " order by exectime desc"
  sum = "select sum(number) As 数量, sum(selfallmoney) As 金额 from AdviceListView where roomcode=2000 and hoscode like '" _
           & Text1.Text & "%" & "' "


  '判断连接的状态
  If cnn.State = adStateOpen Then
  Set rs1.ActiveConnection = cnn
  rs1.CursorType = adOpenStatic
  rs1.Open sql
  Set rs2.ActiveConnection = cnn
  rs2.CursorType = adOpenStatic
  rs2.Open sum
  
  '打开记录集,将从表Users中读取的结果集保存到记录集Adodc1中
   Adodc1.ConnectionString = cnn
   Adodc1.RecordSource = sql
  Adodc1.Refresh
  '打开记录集,将从表Users中读取的结果集保存到记录集Adodc2中
  Adodc2.ConnectionString = cnn
   Adodc2.RecordSource = sum
  Adodc2.Refresh
  
   '显示记录集中记录的数据
   If rs2.Fields(0) <> "" Then
    Label1.Caption = rs2.Fields(0)
    Else
    Label1.Caption = ""
  End If
    If rs2.Fields(1) <> "" Then
    Label2.Caption = rs2.Fields(1)
    Else
    Label2.Caption = ""
  End If
  '关闭记录集
rs1.Close
rs2.Close
  '关闭cnn对象
cnn.Close
End If
End Sub
以前我用Adodc绑定时,sql = "select offname as 科室,hoscode as 住院号,patname as 病人姓名,medname As 药品名称, medspec As 规格, roomunit As 单位, roomprice As 单价, number As 数量, selfallmoney As 金额, sendopecode As 发药人, exectime As 发药时间 from AdviceListView where roomcode=2000 and sendopecode>0 " & _
           "and hoscode like '" & Text1.Text & "%" & "' " & _
           " and offname like'" & Combo1.Text & "%" & "' " & _
           " and medname like'" & Text2.Text & "%" & "' " & _
           " order by exectime desc"
运行可以,现用字符串连接数据库,只有
sql = "select offname as 科室,hoscode as 住院号,patname as 病人姓名,medname As 药品名称, medspec As 规格, roomunit As 单位, roomprice As 单价, number As 数量, selfallmoney As 金额, sendopecode As 发药人, exectime As 发药时间 from AdviceListView where roomcode=2000 and sendopecode>0 " & _
           "and hoscode like '" & Text1.Text & "%" & "' " & _
                " order by exectime desc"
时可以查询到数据,加上 " and offname like'" & Combo1.Text & "%" & "' " & _
           " and medname like'" & Text2.Text & "%" & "' " & _
后,查询不到数据,也没有报错,当三个条件同时满足时才行,为什么不可单个查询。
在查询分析器上运行可以,请版主帮我看一下。
2008-8-5 09:53
octillion
Rank: 3Rank: 3
等级:中级会员
帖子:195
积分:2156
注册:2008-7-24

版主惹你了是吧?
2008-8-5 11:36
simpson
Rank: 4
等级:高级会员
帖子:775
积分:7938
威望:5
注册:2006-11-16

我也觉得   别人不是没事做
2008-8-5 21:01
共有 209 人关注过本帖
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.046005 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved