将表格绑定到存储过程 [英] Binding Forms to Stored Procedures

查看:71
本文介绍了将表格绑定到存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VBA / ADODB将Access 2010表单绑定到存储过程,这不是我以前做过的事情。  (存储过程是SQL Server中相当复杂的CTE。 ) 我得到"运行时错误430.类没有
支持自动化或不支持预期的接口"当我设置表单的记录集时。


任何人都可以帮忙吗? VBA如下所示:


 
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd < span style ="color:Blue;"> As ADODB.Command

设置 cn = ADODB.Connection

使用 cn
.ConnectionString = " DSN = KitchenDB"
。打开
结束 使用

设置 rs = ADODB.Recordset
使用 rs
设置 .ActiveConnection = cn
.Source = "EXEC sp_BatchIntermediateProducts"&#span>& " 1"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
。打开
结束 使用

设置 Me .Recordset = rs '******此语句出错***** **************

设置 rs = 没什么
设置 cn = Nothing


解决方案

您可以向表单添加DatagridView,然后连接DataGridview到您的数据源。 请参阅下面的网页


http://msdn.microsoft.com/en-US/library/fbk67b6z(v = VS.90)的.aspx


I am trying to bind an Access 2010 form using VBA/ADODB to a stored procedure which is not something I have done before.  (The stored procedure is a fairly complex CTE in SQL Server.)  I am getting "Run time error 430. Class does not support automation or does not support expected interface" when I set the form's recordset.

Can anyone help please? The VBA is shown below:

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
      
   Set cn = New ADODB.Connection

   With cn
        .ConnectionString = "DSN=KitchenDB"
        .Open
   End With

   Set rs = New ADODB.Recordset
   With rs
      Set .ActiveConnection = cn
      .Source = "EXEC sp_BatchIntermediateProducts " & "1"
      .LockType = adLockOptimistic
      .CursorType = adOpenKeyset
      .Open
   End With
   
    Set Me.Recordset = rs  '******Error occurs on this statement *******************
     
   Set rs = Nothing
   Set cn = Nothing
   

解决方案

You can add a DatagridView to your form and then connect the DataGridview to your data source.  See webpage below

http://msdn.microsoft.com/en-US/library/fbk67b6z(v=VS.90).aspx


这篇关于将表格绑定到存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆