惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - 嘻哈

招聘asp.net 今天春分 Configure Search On MOSS 2007 (Microsoft Office SharePoint Server) WSS (Windows SharePoint Services) "该搜索请求无法连接到搜索服务" 错误解决 MOSS的备份与还原 How to fix: Recieve error "Unable to display this Web Part" on Data Views after restoring site from backup - 嘻哈 How to change service accounts and service account passwords in SharePoint Server 2007 and in Windows SharePoint Services 3.0 Web 设计工具箱:130 个 Web 设计工具 解决MOSS搜索问题 需求从抱怨开始 ie8 sharepoint 2007 模板安装方法 有杭州的.net高手吗?——续 说点题外话,关于求职简历 有杭州的.Net高手嘛? TechNet Virtual Lab: Microsoft Office SharePoint Portal Server 2003 How to create a SharePoint List using Excel 2003(转贴) FreeTextBox编辑器的问题 升级到FreeTextBox 3.0
[转贴]How to work with stored procedures by using script in an Office InfoPath 2003 form
嘻哈 · 2005-06-28 · via 博客园 - 嘻哈

好久没有更新了。现在先转一个大家都用得到的东东。

Article ID : 827007
Last Review : April 19, 2005
Revision : 2.0

SUMMARY

This article describes step-by-step instructions for creating a Microsoft Office InfoPath 2003 form that works with parameterized stored procedures.

MORE INFORMATION

The top-level XDocument object for InfoPath exposes the QueryAdapter property. The QueryAdapter property returns a reference to the data adapter object that is associated with an InfoPath form. At run time, you can use the QueryAdapter property to access the primary data source of your form and to then run commands. You can use the QueryAdapter property to run a stored procedure that returns records or submits records on your form. This is described in the following sections.

Design a form that uses a stored procedure to query data

Create a new form from a data source

1. Start InfoPath.
2. On the File menu, click Design a Form.
3. In the Design a Form task pane, click New from Data Source.

The Data Source Setup Wizard starts.

4. Choose Database for the data source, and then click Next.
5. Click Select Database.

The Select Data Source dialog box appears.

6. Click New Source.

The Data Connection Wizard appears.

7. Click Microsoft SQL Server, and then click Next.
8. Provide your server name and your logon credentials, and then click Next.
9. Choose the Pubs database, choose the titleauthor table, and then click Next.
10. Click Finish to complete the Data Connection Wizard.

You are returned to the Select Data Source dialog box.

11. In the Select Data Source dialog box, click Open.

You are returned to the Data Source Setup Wizard.

12. Click Next.
13. Select Design data view first, and then click Finish to complete the Data Source Setup Wizard.

Design the query for your form

1. In the Data Source task pane, right-click myFields, and then click Add.

The Add Field or Group dialog box appears.

2. Name the new field myPercentage, and then click OK.
3. Move the myPercentage field to your form.
4. In the Controls task pane, double-click the Button control to insert a button.
5. In the Layout task pane, double-click Two-Column Table to add a table to your form.
6. In the Data Source task pane, click dataFields, and then click d:titleauthor.
7. Move :au_id to the first column of your table. Move :title_id to the second column of your table.
8. Right-click the button on your form, and then click Button Properties.

The Button Properties dialog box appears.

9. In the Label box, type Query, and then click Apply.
10. Click Microsoft Script Editor.

Microsoft Script Editor opens.

11. Add the following code to the OnClick event handler for your query button:
//Retrieve the value of the field that you want to use as a parameter
//to the stored procedure.
var percentageValue = XDocument.DOM.selectSingleNode("/dfs:myFields/my:myPercentage").text;

//Set the Command for the Query Adapter of the Data Source. Incorporate the
//parameter values that you want to use.
XDocument.QueryAdapter.Command = 'execute "dbo"."byroyalty" ' + percentageValue;

//Query the Data Source.
XDocument.Query();
12. Save your form template.

Test the query function for the form

1. Click Preview Form.
2. Type 100 in the My Percentage box, and then click the query button.

The records that match the royalty percentage of 100% appear.

3. Repeat the previous step with other percentage amounts.

For example, you can try 25, 50, and 75 to find the records that match the royalty percentage for 25%, 50%, and 75%.

Design a form that uses a stored procedure to submit data

Create a new form from a Data Source

Follow the steps in the Design a form that uses a store procedure to query data section to create a new form.

Create the stored procedure

1. Start SQL Query Analyzer.
2. Provide your server name and your logon credentials, and then click OK.
3. Execute the following SQL statement:
use pubs
GO
sp_helpconstraint titleauthor
GO
The constraints information for table titleauthor appears.
4. Execute the following SQL statement:
ALTER TABLE titleauthor DROP CONSTRAINT ForeignKeyConstraints

Note ForeignKeyConstraints is the constraint for FOREIGN KEY constraint definition that you obtain in step3.
5. Create the addnewauthor stored procedure by using the following SQL statement:
create PROCEDURE addnewauthor @id varchar(11),@title varchar(6),@order tinyint,@royaltyper int
AS
SET IMPLICIT_TRANSACTIONS off
INSERT INTO titleauthor values (@id,@title,@order,@royaltyper)

Design the Submit function for your form

1. In the Controls task pane, double-click the Button control to insert a button for executing the stored procedure.
2. In the Data Source task pane, right-click d:titleauthor, and then click More.
3. In the Select a Control box, click Controls in Layout Table, and then click OK.
4. Right-click the button on your form, and then click Button Properties.

The Button Properties dialog box appears.

5. In the Label box, type Submit, and then click Apply.
6. Click Microsoft Script Editor.

Microsoft Script Editor opens.

7. Add the following code to the OnClick event handler for your submit button:
//Retrieve the value of the field that you want to use as a parameter
//to the stored procedure.
var id = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:titleauthor/@au_id").text;
var title = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:titleauthor/@title_id").text;
var order = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:titleauthor/@au_ord").text;
var royaltyper = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:titleauthor/@royaltyper").text;

//Set the Command for the Query Adapter of the Data Source. Incorporate the
//parameter values that you want to use.
XDocument.QueryAdapter.Command = "execute addnewauthor " + "'" + id + "',"+"'"+title+"',"+"'"+order+"',"+"'"+royaltyper+"'";

//Query the Data Source.
XDocument.Query();
8. Save your form template.

Test the Submit function for the form

1. Type 172-32-1172 in the Au Id box, type BU1031 in the Title Id box, type 2 in the Au Ord box, and type 120 in the Royaltyper box.
2. Click the submit button.
3. In SQL Query Analyzer, execute the following SQL statement:
select * from titleauthor where au_id = '172-32-1172'
The data is inserted into the titleauthor table.

APPLIES TO
Microsoft Office InfoPath 2003
Microsoft Office InfoPath 2003, Service Pack 1 (SP1)