vb调用存储过程,返回值。这段程序到底问题出在哪??

user 2011-05-17 10:27:15
Private Sub commandbutton1_Click()
Dim i As Integer, sht As Worksheet
Dim cn As New adodb.Connection
Dim rs As New adodb.Recordset
Dim strCn As String, strSQL As String
Set sht = ThisWorkbook.Worksheets("sheet1")
strCn = "Provider=sqloledb;Server=jzdata;Database=ufdata_2011" + ";Uid=sa;Pwd=pass;"

cn.Open strCn '与数据库建立连接,如果成功,返回连接对象cn
Set g_Cmd = New Command
g_Cmd.ActiveConnection = strCn ' 连接到数据库
g_Cmd.CommandType = adCmdStoredProc ' 表示cmd的类型为存储过程
g_Cmd.CommandText = "GL_P_FSEYEB" ' 调用存储过程

g_Cmd.Parameters(1) = "1"
g_Cmd.Parameters(2) = "5"
g_Cmd.Parameters(3) = 0
g_Cmd.Parameters(4) = Null
g_Cmd.Parameters(5) = "我"
g_Cmd.Parameters(6) = 1
g_Cmd.Parameters(7) = 3
g_Cmd.Parameters(8) = 0
g_Cmd.Parameters(9) = Null
g_Cmd.Parameters(10) = Null
g_Cmd.Parameters(11) = Null
g_Cmd.Parameters(12) = Null
g_Cmd.Parameters(13) = "case when cclass ='资产' then 1 else case when cclass ='负债' then 2 else case when cclass ='权益' then 3 else case when cclass ='成本' then 4 else 5 end end end end as lx"
g_Cmd.Parameters(14) = "YEB26753"
g_Cmd.Parameters(15) = Null
Set g_Rs = g_Cmd.Execute ' 执行存储过程 把数据库查询结果返回给数据集
rs.Open g_Cmd.Execute, cn '执行strSQL所含的SQL命令,结果保存在rs记录集对象中。此行运行时错误,提示:超时已过期。
i = 5
Do While Not rs.EOF '当数据指针未移到记录集末尾时,循环下列操作
sht.Cells(i, 1) = rs(1)
sht.Cells(i, 2) = rs(2)
sht.Cells(i, 3) = rs(3)
sht.Cells(i, 4) = rs(4)
sht.Cells(i, 5) = rs(5)
sht.Cells(i, 6) = rs(6)
sht.Cells(i, 7) = rs(7)
sht.Cells(i, 8) = rs(8)
sht.Cells(i, 9) = rs(9)

rs.MoveNext '移向下一条记录
i = i + 1
Loop
rs.Close
cn.Close
MsgBox "查询完毕!"
End Sub
...全文
180 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
啊的发哦 2011-05-18
  • 打赏
  • 举报
回复
结帖率:0.00%
lliai 2011-05-18
  • 打赏
  • 举报
回复
直接写程序算了。其实书中都有。
cqq_chen 2011-05-18
  • 打赏
  • 举报
回复
看书吧!!!
vbman2003 2011-05-18
  • 打赏
  • 举报
回复
前面同样一贴才回复,又来一贴....
说实在,特别让人讨厌....
而且这种人大多只是急于要答案,多数不结贴,闪了....
user 2011-05-18
  • 打赏
  • 举报
回复
不是不结贴啊。

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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