Linq to sql 将var数据转换为哈希表

Linq to sql 将var数据转换为哈希表,linq-to-sql,Linq To Sql,是否可以将var数据转换为哈希表 Hashtable hsTest = new Hashtable(); var oFeat = (from t in db.test where t.Product_ID == iProductID select t); 假设您希望使用Product_ID作为哈希表中的键,并使用Product_Name之类的内容作为值。你可以这样做: Hashtable hsT

是否可以将var数据转换为哈希表

Hashtable hsTest = new Hashtable();
        var oFeat = (from t in db.test
                     where t.Product_ID == iProductID
                     select t);

假设您希望使用Product_ID作为哈希表中的键,并使用Product_Name之类的内容作为值。你可以这样做:

Hashtable hsTest = new Hashtable ();
var oFeat = (from t in db.test
             where t.Product_ID == iProductID
             select t);
foreach (var product in oFeat) {
    hsTest[product.Product_ID] = product.Product_Name;
}

我有一个文本框和一个按钮。在Button中,单击gridview中的文本框条目。但我希望没有数据库条目。为此,我尝试使用哈希表。谁能告诉我怎么做吗?是的。请在此处查看ToDictionary()方法: