如何将Dictionary转换成datatable-CSDN论坛
答案:2 悬赏:80 手机版
解决时间 2021-03-19 03:17
- 提问者网友:临风不自傲
- 2021-03-18 08:20
如何将Dictionary转换成datatable-CSDN论坛
最佳答案
- 五星知识达人网友:独钓一江月
- 2021-03-18 09:09
DepartmentManage dm = new DepartmentManage();
Dictionary dicDep = new Dictionary();
private void DepartmentForm_Load(object sender, EventArgs e)
{
dicDep = (Dictionary)dm.query().RetValue;
DataTable dt = new DataTable();
dt.Columns.Add("ID",typeof(Guid));
dt.Columns.Add("DID",typeof(string));
dt.Columns.Add("DEPARTMENTNUM",typeof(string));
dt.Columns.Add("DEPARTMENTNAME",typeof(string));
dt.Columns.Add("REMARKS",typeof(string));
foreach (KeyValuePair item in dicDep)
{
DataRow dr = dt.NewRow();
dr["ID"] = ...;
dr["DID"] = ...;
dr["DEPARTMENTNUM"] = ...;
dr["DEPARTMENTNAME"] = ...;
dr["REMARKS"] = ...;
dt.Rows.Add(dr);
}
}
Dictionary
private void DepartmentForm_Load(object sender, EventArgs e)
{
dicDep = (Dictionary
DataTable dt = new DataTable();
dt.Columns.Add("ID",typeof(Guid));
dt.Columns.Add("DID",typeof(string));
dt.Columns.Add("DEPARTMENTNUM",typeof(string));
dt.Columns.Add("DEPARTMENTNAME",typeof(string));
dt.Columns.Add("REMARKS",typeof(string));
foreach (KeyValuePair
{
DataRow dr = dt.NewRow();
dr["ID"] = ...;
dr["DID"] = ...;
dr["DEPARTMENTNUM"] = ...;
dr["DEPARTMENTNAME"] = ...;
dr["REMARKS"] = ...;
dt.Rows.Add(dr);
}
}
全部回答
- 1楼网友:蓝房子
- 2021-03-18 10:44
dictionary dict = new dictionary();
dict.add("keyone", "one");
dict.add("keytwo", "two");
datatable dt = new datatable();
datacolumn dc1 = new datacolumn("columnone");
datacolumn dc2 = new datacolumn("columntwo");
dt.columns.add(dc1);
dt.columns.add(dc2);
foreach (keyvaluepair item in dict)
{
dt.rows.add(item.key,item.value);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯