我需要开发Access窗体来传递参数来调用Sql Server存储过程,并且需要显示输出。 例如:我有两个参数:“开始日期”,并从访问表“终止日期” 我需要通过这些日期和EXCUTE SQL Server存储过程和输出应该显示..如何使用Ms-Access窗体通过传递参数执行Sql server存储过程
请帮我...请帮助我一步一步,我是这个新的访问应用程序
我需要开发Access窗体来传递参数来调用Sql Server存储过程,并且需要显示输出。 例如:我有两个参数:“开始日期”,并从访问表“终止日期” 我需要通过这些日期和EXCUTE SQL Server存储过程和输出应该显示..如何使用Ms-Access窗体通过传递参数执行Sql server存储过程
请帮我...请帮助我一步一步,我是这个新的访问应用程序
我在访问几年前做了类似的事情。您需要查看通过ODBC查询。这将允许您从Access执行SQL存储过程。
请访问以下链接: http://support.microsoft.com/kb/303968
我不知道你将如何度过,虽然传递的参数,但我相信,如果你谷歌“通过ODBC查询访问存储过程的参数”,你会发现一些线索。对不起,我的记忆对于确切的细节有点淡化。
这取决于你的存储过程的输出类型,但基本上,说你要显示你的存储过程myProc
到调试控制台的结果,你可以这样做:
Sub printMyProcResults(startDate as Date, endDate as Date)
Dim db as DAO.Database
Dim qf as DAO.QueryDef
Dim rs as DAO.Recordset
Set db = CurrentDb()
Set qf = db.CreateQueryDef("")
' Set to true if your stored procedure returns something, otherwise, '
' set to False '
qf.ReturnsRecords = True
' You need to adjust this to whatever your SQL server instance name is '
' and whatever your database name is '
' This connection string will use the local machine's user credentials '
' to connect to the server, change as appropriate '
qf.Connect = "ODBC;DRIVER=SQL Server;SERVER=MYSERVER;Trusted_Connection=Yes;DATABASE=MYDATABASE;"
' We construct the SQL to call the procedure. Update this to suit your '
' actual proc name '
qf.SQL = "myStoredProc '" & Format(startDate, "dd mmm yyyy") & "'," & _
"'" & Format(endDate, "dd mmm yyyy") & "'"
' Open the recordset to access the results '
Set rs = qf.OpenRecordSet()
' Print the result to the debug console '
' Of course, you need to adapt this to your own case '
Do While Not rs.EOF
debug.print rs(0)
rs.MoveNext
Loop
rs.Close
' Cleanup '
Set rs = Nothing
Set qf = Nothing
Set db = Nothing
End Sub
连接字符串,您可能需要根据您的SQL Server配置来调整它:取决于SQL Server的配置方式:http://connectionstrings.com/sql-server-2008
我想从使用访问表单访问sql server存储过程传递参数,并应获取Access..please帮助详细步骤 – user1292427 2012-03-26 12:16:35
上述代码中有几个问题。 db被定义两次。查询拼写错误'CreateQeuryDef'。也相信ReturnRecords应该是ReturnRecords – 2015-06-03 16:53:09
@ChrisNevill代码更新与您的意见。感谢您指出问题。 – 2015-06-11 19:55:55
但是如何从Access窗体连接sql server 2008以调用存储过程并传递参数。步骤如何实现.i用2个测试框(startdate,enddate)和一个按钮创建窗体。接下来要做什么来传递p参数到Sql服务器盯着过程,并得到输出 – user1292427 2012-03-26 07:55:50
你需要一个从ODBC访问SQL的连接去这个链接并阅读它http://accessexperts.net/blog/2011/07/29/sql-server-stored-procedure-指南 - 微软的访问部分1/ – Namphibian 2012-03-26 07:59:36
我在控制面板 - >管理工具中创建了odbc连接。我无法弄清楚如何通过传递参数从Access中获取输出 – user1292427 2012-03-26 08:41:36