我有visual studio 2012 windows形式的c#和Xampp服务器。我已经定义了一个二维字典,其中存储了值。 这就是我的字典结构:
社会ID - >请求号码 - >服务类别,服务类型,状态
在myphpmyadmin中有一个表具有相同的列名,即(社会ID,请求号,服务类别,服务类型,状态)。只填充了社会id列。表中的社会id值在字典中是相同的
我的问题是:我想在数据库表的相应字段中获取并存储字典的值。
这是我的代码:
public class Map
{
public string date_creat { get; set; }
public string date_Modif { get; set; }
public string ServiceCgr { get; set; }
public string ServiceTyp { get; set; }
public string Req_status { get; set; }
}
Dictionary<string, Dictionary<string, List<Map>>> dic = new Dictionary<string, Dictionary<string, List<Map>>>();
Map mp=new Map();
while (reader.Read())
{
Req_nber = reader["request_number"].ToString();
society = reader["pincode"].ToString();
mp.date_creat = reader["date_created"].ToString();
mp.date_Modif = reader["date_modified"].ToString();
mp.ServiceCgr = reader["service_category"].ToString();
mp.ServiceTyp = reader["service_type"].ToString();
mp.Req_status = reader["request_status"].ToString();
//if pincode or society already exists
if (dic.ContainsKey(society)) //2nd if
{
//if request number already exists
if (dic[society].ContainsKey(Req_nber))
{
//add records
dic[society][Req_nber].Add(mp);
}
//else part
else // if we get a new request number
{
//rnumber is added and value part is newed up
dic[society].Add(Req_nber, new List<Map>());
//record is added into list
dic[society][Req_nber].Add(mp);
}
}//end 2nd if
else//if we get a new society
{
//pcode is added and value part is newed up
dic.Add(society, new Dictionary<string, List<Map>>());
//rnumber is added and value part is newed up
dic[society].Add(Req_nber, new List<Map>());
//record is added into list
dic[society][Req_nber].Add(mp);
}
}//end while