我有我的DataGridView.DataSource一個問題,它已經消耗了我大量的時間解決這個問題。以下是代碼:爲什麼我的DataGridView DataSource沒有繪製行?
string[] queryWords = singleQuery.Split(' '); // Split the query words according the "space" character
// Compose the SQL select query
string selectClause = @"SELECT ID, CategoryID, Name, UnitID, Price, QuantityAgen, QuantityBanjer, QuantityMalalayang, QuantitySorong FROM Product WHERE ";
// Add the where clauses inside the SQL select query
for (int i = 0; i < queryWords.Length; i++)
{
selectClause += "(Name LIKE '%" + queryWords[i] + "%')";
if (i < queryWords.Length - 1)
selectClause += " AND ";
}
// Initiate the query and get the appropriate results
IEnumerable<SumberRejekiProgram.Code.Product> resultQuery = dbProduct.ExecuteQuery<SumberRejekiProgram.Code.Product>(selectClause);
var finalResult = from p in resultQuery
select new { Name = p.Name, Price = p.Price, Unit = p.Unit.Name };
// Bind the DataGridView according to the final query result in resultQuery variable
dgvSearch.DataSource = resultQuery;
當我調試代碼時,「resultQuery」和「finalResult」都包含我想要的結果。但是,當我設置「dgvSearch.DataSource」,結果不會出現在該行中,即使我嘗試都dgvSearch.DataSource = resultQuery
和dgvSearch.DataSource = finalResult
。 DataGridView只是空的(列除外)。
我調試「dgvSearch」的代碼執行後,以確保數據源工作正常,且它。所有的結果都在DataSource中,但不知何故DataGridView將不會顯示它,儘管我已經調用了dgvSearch.show()
。
任何人都可以幫助我嗎?我覺得我想要自殺T_T。 非常感謝你提前。
爲什麼你認爲應該有人幫助你,如果你不感謝他? – abatishchev 2011-04-20 11:27:14