如何使用ms access 2010 VBA中的参数调用SQL Server存储过程 [英] How to call SQL server stored procedure with parameter in ms access 2010 VBA
本文介绍了如何使用ms access 2010 VBA中的参数调用SQL Server存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MS Access应用程序,其中包含链接到SQL Server的所有表,因此在MS Access VBA代码中,我使用这些表非常简单,我通过名称访问它们,如 [Customers]
。
我还在SQL Server中有一个名为 sp_CopyData
的存储过程,我需要这个从我的VBA代码打电话。我希望在VBA中按姓名搜索。
谢谢
我尝试过:
I have an MS Access application that contains all tables linked to SQL Server, so in MS Access VBA code I work with those tables very simple, I access them via name, like [Customers]
.
Also I have a stored procedure in SQL Server called sp_CopyData
which I need to call from my VBA code. I want search by name in VBA.
thanks
What I have tried:
Create PROCEDURE [dbo].[sp_searchh]
@CustomersName varchar(50)
AS
BEGIN
select Id,age,salary,CustomersName from Table1 where CustomersName =(@CustomersName)
END
推荐答案
您可以使用与普通表格相同的方式过滤链接表格中的数据在MS Access中,例如使用参数 [ ^ ]
You can filter data from linked tables the same way you do that with "normal" tables in MS Access, for example by using Parameters[^]
PARAMETERS [cusname] CHAR;
SELECT C.Id, C.age, C.salary, C.CustomersName
FROM [Customers] AS C
WHERE C.CustomersName = [cusname];
结论:您不需要编写代码来从MS SQL Server获取数据,因为数据已经链接到MS Access数据库。
详情请见:
关于使用代码中的参数的一切 [ ^ ]
Access 2007中的查询提示和技巧 [ ^ ]
这篇关于如何使用ms access 2010 VBA中的参数调用SQL Server存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文