我的数据库表如下所示:
Room Item Description
------------------------------------
Bedroom Chair Leather
Bedroom Bed Comfortable
Office Desk Very Small
Office Book Shelf Lot of Books
我想将此数据库表填充到以下 Dictionary 类型对象中
Dictionary<string, Dictionary<string,string>
我该怎么做呢?
我开始按如下方式编写代码,但由于我不知道如何正确填充它,所以我无法继续。
Dictionary<string, Dictionary<string,string>> roomfurnitures= new Dictionary<string,Dictionary<string, string>>();
Dictionary<string, string> furniture= new Dictionary<string, string>();
using (SqlDataReader reader = this.m_cmdGetFurnitureByRoom.ExecuteReader())
{
while (reader.Read())
{
string roomtype = reader.GetString(reader.GetOrdinal("Room"));
string item = reader.GetString(reader.GetOrdinal("Item"));
string description = reader.GetString(reader.GetOrdinal("Description"));
//I do not know how to populate the roomfurnitures dictionary poperly
}
}
正确填充 roomfurnitures 字典后,我希望它看起来像这样。请帮忙。
Bedroom Chair Leather
Bed Comfortable
Office Desk VerySmall
BookShelf Lot of Books