2011-12-05 28 views
-2

イム次のコード:上記のコードでSharePoint 2010リストのCAMLクエリ?

string xpathresultBTADSLMAX = "BT/Max Standard"; 

if (xpathresult2 == "BT ADSL Max") 
{ 

//Creating the CAML query to perfomr the query on the list to find the required values 
SPQuery query = new SPQuery(); 

//try to find items in this list that matches the result of the XPATH query performed 
earlier 
//in this case "BT/Standard" 
string camlquery = @"<Query> 
<Where> 
<Eq> 
<FieldRef Name='Vendor_x0020_Product_x0020_Name'/> 
<Value Type='Text'>" + xpathresultBTADSLMAX + @"</Value> 
</Eq> 
</Where> 
</Query>"; 

query.Query = camlquery; 
query.ViewFields = "<FieldRef Name='Fabric_x0020_Name'/><FieldRef 
Name='Defined_x0020_For/><FieldRef name='MPLS'/>"; //selecting only the required 
fields 
from the CAML query 

SPListItemCollection listItemCollection = list.GetItems(query); 


//string fabricName = (string)item["Fabric_x0020_Name"]; commented out temporarily 

//string definedFor = (string)item["Defined_x0020_For"]; commented out temporarily 

string fabricName = (string)item["Fabric_x0020_Name"]; 
string definedFor = (string)item["Defined_x0020_For"]; 

AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(fabricName, definedFor 
)); 

} 

私は、「BT /最大標準」のベンダーな生産名前を持つリスト項目から特定の情報を表示しようとしています。私が表示したい値は、現在 "Fabric Name"と "Defined For"です。

リテラルコントロールを追加するだけで、aspプレースホルダーに表示できるようにしたいが、単純に機能しないようにしたい。ここで間違っていることはありますか?これを達成するための提案をお願いします。

多くのThansが先行しています!

UPDATED!

私はコードにいくつかの変更を加えました。これは基本的に前述の問題を修正しました。私は現在、aspプレースホルダにCAMLクエリの結果を表示することを諦めています。

string xpathresultBTADSLMAX = "BT/Max Standard"; 

//Executing the correct query based on a if condition for BT ADSL 
if (xpathresult2 == "BT ADSL Max") 
{ 

//Creating the CAML query to perfomr the query on the list to find the required values 
SPQuery query = new SPQuery(); 

//try to find items in this list that matches the result of the XPATH query performed 
earlier 
//in this case "BT/Standard" 
string camlquery = @"<Query> 
<Where> 
<Eq> 
<FieldRef Name='Vendor_x0020_Product_x0020_Name'/> 
<Value Type='Text'>" + xpathresultBTADSLMAX + @"</Value> 
</Eq> 
</Where> 
</Query>"; 

query.Query = camlquery; 
//query.ViewFields = "<FieldRef Name='Fabric_x0020_Name'/><FieldRef 
Name='Defined_x0020_For'/><FieldRef name='MPLS'/>"; //selecting only the required 
fields from the CAML query, GIVES ERROR 

SPListItemCollection listItemCollection = list.GetItems(query); 


//string fabricName = (string)item["Fabric_x0020_Name"]; commented out temporarily 

//string definedFor = (string)item["Defined_x0020_For"]; 
//string feniedFor = (string)item["Defined_x0020_For"]; 



//AvailabilityCheckerResults3.Controls.Add(new LiteralControl(fabricName + " " + 
definedFor)); 

//AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(fabricName)); 
commented out temporarily 

//string fabricName = (string)listItemCollection["Fabric_x0020_Name"].ToString; 

/*string fabricName = listItemCollection.ToString(); 

AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(fabricName));*/ 



foreach (SPListItem item in listItemCollection) 
{ 
try 
{ 

string results56 = (string)item["Fabric_x0020_Name"] + " " + 
(string)item["Defined_x0020_For"] + " " + "<b>MPLS:</b> " + (string)item["MPLS"] + 
"<br/>" + "<br/>"; 
AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(results56)); 
} 
catch (Exception err) 
{ 
AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(err.ToString())); 
} 
} 

} 

しかし、今私はリストからすべてのリコーコードを手に入れているという点で別の問題があります。これは意図した結果ではありません。ここでは、出力は次のようになります。

アルパカ はのための汚いADSL製品:CCTVサードパーティ製のリモートアクセスインタラクティブモデルやウェブサイトのテスト MPLS:いいえ

バーネット ホームユーザー& SOHO製品(< 5ユーザサイト) < 2つの同時コールで5つのVoIP接続をサポートできます。 IPTパッケージ MPLS:はい

CAMLクエリは「アルパカ」の結果のみを表示する必要があります。リスト内のすべてのアイテムではなく、必要なアイテムのみを取得するにはどうすればよいですか?おそらく何か間違っています!

多くのおかげ

答えて

0

はこれでもう一度試してみてください - あなたの変数camlquery

+0

私がタグを使用している理由は、完全な結果を戻すためです。次に、結果セットから特定の値を選択するために、(query.ViewFields = "";私が持っている問題は、結果をASPコントロールに表示させる方法を確かめないことです。 –

+0

データを取得しているかどうかチェックしましたか? –

+0

はい結果を得ているIm! –

2

から囲まれたクエリタグを削除する構文 にクエリタグを含めることはありませんすることができます。この

string camlquery = @"<Where><Eq><FieldRef Name='Vendor_x0020_Product_x0020_Name'/> 
         <Value Type='Text'>" + xpathresultBTADSLMAX + @"</Value> 
         </Eq> 
        </Where>"; 

詳細を試してみてくださいこれを芸術的に見るhttp://rmanimaran.wordpress.com/2011/03/11/new-in-sharepoint-2010-caml-query/

ホップ助けてくれます。

関連する問題