vba中调用sql存储过程,返回数据集?求解!解决思路

fieldset{padding:10px;}

vba中调用sql存储过程,返回数据集?求解!Private Sub commandbutton1_Click()Dim i As Integer, sht As Worksheet ‘i为整数变量;sht 为excel工作表对象变量,指向某一工作表Dim cn As New adodb.Connection ‘定义数据链接对象 ,保存连接数据库信息;请先添加ADO引用Dim rs As New adodb.Recordset ‘定义记录集对象,保存数据表Dim strCn As String, strSQL As String ‘字符串变量Set sht = ThisWorkbook.Worksheets("sheet1")strCn = "Provider=sqloledb;Server=ipsundb;Database=ufdata_100_2011" + ";Uid=sa;Pwd=W8c2w8a0;"”strSQL = " select ccode,ccode_name,cexch_name,sbb,sbb1,smd,smc,sld,slc from GL_P_FSEYEB"cn.Open strCn ‘与数据库建立连接,如果成功,返回连接对象cnSet g_Cmd = New Commandg_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) = 0g_Cmd.Parameters(4) = Nullg_Cmd.Parameters(5) = "我"g_Cmd.Parameters(6) = 1g_Cmd.Parameters(7) = 3g_Cmd.Parameters(8) = 0g_Cmd.Parameters(9) = Nullg_Cmd.Parameters(10) = Nullg_Cmd.Parameters(11) = Nullg_Cmd.Parameters(12) = Nullg_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) = NullSet g_Rs = g_Cmd.Execute ‘ 执行存储过程 把数据库查询结果返回给数据集rs.Open g_Cmd.Execute, cn ‘执行strSQL所含的SQL命令,结果保存在rs记录集对象中。此行运行时错误,提示:超时已过期。 i = 5Do 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 + 1Looprs.Closecn.Close ‘关闭数据库链接,释放资源MsgBox "查询完毕!"End Sub——解决方案——————————————————–二楼给删除了?没有行李,没有背包,不带电脑更不要手机,

vba中调用sql存储过程,返回数据集?求解!解决思路

相关文章:

你感兴趣的文章:

标签云: