将数据动态加载到 InfoPath 2007 中的下拉列表框时出现问题?

发布于 2024-09-07 05:25:34 字数 1070 浏览 6 评论 0原文

我的 InfoPath 表单中有一个下拉列表,我正在根据下拉列表的选择加载一些其他字段。这样我就为下拉列表的“更改”事件编写了如下代码。

public void ProjectName_Changed(object sender, XmlEventArgs e)
{
            string projectId = e.NewValue;
            dataQueryConnection = (AdoQueryConnection)this.DataConnections["ProjectInformation"];
            dataQueryConnection.Command = dataQueryConnection.Command + string.Format(" WHERE ProjectId = '{0}'",             projectId);
            dataQueryConnection.Execute();

}

第一次当我更改下拉列表中的项目时,它工作正常,但对于项目的后续更改(第二次等),它会给出以下错误,

无法运行查询 以下数据对象: ProjectInformation InfoPath 无法运行 指定的查询。 [0x80040E14][Microsoft OLE DB 提供程序 对于 SQL Server] 附近语法不正确 关键字“WHERE”。

这就是第二次的原因,

dataQueryConnection.Command = 选择 “员工 ID”、“帐户名称”、“项目名称”、“项目 ID”、“项目角色”、“BillableUtilization”、“客户名称”、“账单代码”、“BUHead” 来自“TRF”。“hrt_vw_ProjectInformation” 作为“hrt_vw_ProjectInformation”,其中 项目 ID = '3072507' 其中项目 ID ='3076478'

后续事件触发每次与先前执行的查询一起使用 WHERE 子句。

我怎样才能摆脱这个问题?

I have a Drop-Down list in my InfoPath form and I am loading some other fields based on the selection of the drop-down list. so that I have written code as follows for the "changed" event of the drop down list.

public void ProjectName_Changed(object sender, XmlEventArgs e)
{
            string projectId = e.NewValue;
            dataQueryConnection = (AdoQueryConnection)this.DataConnections["ProjectInformation"];
            dataQueryConnection.Command = dataQueryConnection.Command + string.Format(" WHERE ProjectId = '{0}'",             projectId);
            dataQueryConnection.Execute();

}

For the first time when I change an item in the drop down list its working fine but for the subsequent changes of items(2nd time, etc..) its give the following error,

The query cannot be run for the
following DataObject:
ProjectInformation InfoPath cannot run
the specified query.
[0x80040E14][Microsoft OLE DB Provider
for SQL Server] Incorrect syntax near
the keyword 'WHERE'.

And this is the reason, for the second time,

dataQueryConnection.Command = select
"EmployeeID","Accountname","ProjectName","ProjectId","ProjectRole","BillableUtilization","ClientName","BillingCode","BUHead"
from "TRF"."hrt_vw_ProjectInformation"
as "hrt_vw_ProjectInformation" WHERE
ProjectId = '3072507' WHERE ProjectId
= '3076478'

subsequent event firing biding the WHERE clause every time with the previous executed query.

How I can over come from this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀中猫帐中妖 2024-09-14 05:25:34

将初始命令字符串存储在代码中的全局变量中(在加载事件中)。然后在 Changed 函数中附加到全局变量而不是命令的先前值。

string OrigString

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
   OrigString = dataQueryConnection.Command;
}

public void ProjectName_Changed(object sender, XmlEventArgs e) 
{ 
            string projectId = e.NewValue; 
            dataQueryConnection = (AdoQueryConnection)this.DataConnections["ProjectInformation"]; 
            dataQueryConnection.Command = OrigString + string.Format(" WHERE ProjectId = '{0}'",             projectId); 
            dataQueryConnection.Execute(); 

} 

Store the initial command string in a global variable in your code (in the loading event). Then in your Changed function append to the global variable instead of to the previous value of the command.

string OrigString

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
   OrigString = dataQueryConnection.Command;
}

public void ProjectName_Changed(object sender, XmlEventArgs e) 
{ 
            string projectId = e.NewValue; 
            dataQueryConnection = (AdoQueryConnection)this.DataConnections["ProjectInformation"]; 
            dataQueryConnection.Command = OrigString + string.Format(" WHERE ProjectId = '{0}'",             projectId); 
            dataQueryConnection.Execute(); 

} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文