vb调用存储过程,返回值。这段程序到底问题出在哪??
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
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
...全文
相关推荐
VB.Net调用存储过程并得到返回值
下面我们将详细介绍如何在VB.Net中调用存储过程并得到返回值。一、存储过程的定义存储过程是数据库中的一种程序单元,它可以包含多条SQL语句和控制逻辑。
vb调用存储过程学习
今天上班学习到许多以前没有用到的知识.首先是把前几天vbalExpBar6.ocx调试成功了.需要引用一个SSubTmr6.dll文件.还学会了用VB调用存储过程.实现增;删;改;查功能.下面是一段存储过程比较好的代码:Option ExplicitDim mConn As ADODB.ConnectionDim rs1 As ADODB.RecordsetDim rs2
VB 调用oracle 带返回值的存储过程
当使用VB与Oracle进行交互时,有时候我们需要调用Oracle中的存储过程,尤其是那些带有返回值的存储过程。下面将详细介绍如何在VB中实现这一操作。
VB.NET调用MySQL存储过程并获得返回值的方法
MySQL存储过程支持输入参数、输出参数和返回值。返回值可以通过`SELECT`语句返回,也可以通过`RETURN`语句设置。在VB.NET中,你可以通过上述方法轻松调用这些存储过程,并获取其返回值。
VB.NET 2008调用SQL存储过程并返回值示例
在VB.NET 2008中,调用SQL Server存储过程是常见的数据库操作之一,它允许程序员通过预先定义好的数据库函数来执行复杂的数据处理任务。


VB基础类
