将表格绑定到存储过程 [英] Binding Forms to Stored Procedures
问题描述
我正在尝试使用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屋!