我使用Linq從數據表中選擇數據。選擇將是一個列和要求是功能應返回string[]
。我沒有得到如何將結果轉換爲string[]
。如何將Linq結果轉換爲字符串[]?
請指導,下面是我的代碼:
public string[] GetCompletionList(string prefixText)
{
if (HttpContext.Current.Cache["Dir"] == null)
{
return null;
}
DataTable dt = (DataTable)HttpContext.Current.Cache["Dir"];
var details = from addresses in dt.AsEnumerable()
where SqlMethods.Like(prefixText, prefixText + "%") || SqlMethods.Like(prefixText, "%" + prefixText + "%")
select addresses["Details"];
return details.tol;
}
感謝Oded,我很抱歉,我不太瞭解lambda表達式和Linq。請指導我應該使用此代碼的位置?謝謝你一次。 – haansi 2010-12-16 10:53:08
@haansi - 我只寫了你函數的最後一個return語句。 – Oded 2010-12-16 10:53:49
這裏的Oded是一個錯誤:錯誤'System.Data.EnumerableRowCollection'不包含'ToArray'的定義,並且沒有找到接受類型'System.Data.EnumerableRowCollection '的第一個參數的擴展方法'ToArray'你是否缺少使用指令或程序集引用?) –
haansi
2010-12-16 11:04:15