public static string GetContentFromSPList(string cValueToFind)
{
string cValueFound = "";
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://mysite"))
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList oListAbout = web.Lists["About"];
SPQuery oQuery = new SPQuery();
oQuery.Query = "<OrderBy><FieldRef Name='myField' /></OrderBy><Where><Eq><FieldRef Name='myField' /><Value Type='Choice'>" + cValueToFind + "</Value></Eq></Where>";
SPListItemCollection collListItems = oListAbout.GetItems(oQuery);
foreach (SPListItem oListItem in collListItems)
{
cValueFound = (oListItem["FieldContents"] != null ? oListItem["FieldContents"].ToString() : "");
}
}
}
return cValueFound;
});
//return cValueFound;
}
catch (Exception ex)
{
}
finally
{
//return cValueFound;
}
}
上面是一段代码。这个功能有什么问题。无法返回字符串值
问题不允许返回字符串。它不断给出编译错误。我相信我做错了什么!
谢谢。
你能发布你看到的错误消息吗? –
显然,如果编译器给你一个错误,代码是错误的。奇怪的是,生成的错误信息告诉你到底是什么错误! – Tergiver
我希望'不是所有的代码路径都返回一个值'错误,以......开始...... –