| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 618 人关注过本帖
标题:(查错)请版主来帮个忙
只看楼主 加入收藏
jxawgyl
Rank: 1
等 级:新手上路
帖 子:208
专家分:0
注 册:2007-10-16
结帖率:100%
收藏
 问题点数:0 回复次数:2 
(查错)请版主来帮个忙
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-08-05 09:53
octillion
Rank: 1
等 级:新手上路
帖 子:195
专家分:0
注 册:2008-7-24
收藏
得分:0 
版主惹你了是吧?
2008-08-05 11:36
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 
我也觉得   别人不是没事做

全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2008-08-05 21:01
快速回复:(查错)请版主来帮个忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016458 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved