1

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();

}

ドロップダウンリストのアイテムを初めて変更すると正常に動作しますが、その後のアイテムの変更(2回目など)では、次のエラーが発生します。

次の DataObject に対してクエリを実行できません: ProjectInformation InfoPath は指定されたクエリを実行できません。[0x80040E14][Microsoft OLE DB Provider for SQL Server] キーワード 'WHERE' 付近の構文が正しくありません。

そして、これが理由です。

dataQueryConnection.Command = "TRF"."hrt_vw_ProjectInformation" から "EmployeeID","Accountname","ProjectName","ProjectId","ProjectRole","BillableUtilization","ClientName","BillingCode","BUHead" を選択します。 hrt_vw_ProjectInformation" WHERE ProjectId = '3072507' WHERE ProjectId = '3076478'

前回実行されたクエリで毎回 WHERE 句を入札する後続のイベント起動。

どうすればこの問題を乗り越えることができますか?

4

1 に答える 1

0

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(); 

} 
于 2010-07-01T13:15:31.783 に答える