将数据动态加载到 InfoPath 2007 中的下拉列表框时出现问题?
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将初始命令字符串存储在代码中的全局变量中(在加载事件中)。然后在 Changed 函数中附加到全局变量而不是命令的先前值。
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.