代碼如下://]//]////將列表轉(zhuǎn)換為datatable
//]//]//]//
//
publicstaticdatatabletodatatable
{
propertydescriptorcollectionproperties=TypeDescriptor.GetProperties屬性(typeof(T))
DataTabledt=newDataTable()
用于(inti=0i
{
PropertyDescriptorproperty=properties[i
]dt.Columns.Add列(屬性。名稱,property.PropertyType屬性)
}
object[]values=新對(duì)象[屬性。計(jì)數(shù)
]foreach(數(shù)據(jù)中的T項(xiàng))
{
for(inti=0i
{
values[i]=properties[i].GetValue(item)
}數(shù)據(jù)行添加(values)
}]returnDT
WPF怎么把ListView中的數(shù)據(jù)轉(zhuǎn)換成datatable?如果listview的數(shù)據(jù)源使用datatable類型的數(shù)據(jù),則不需要轉(zhuǎn)換。
listView.ItemDource=數(shù)據(jù)表.默認(rèn)視圖。所以不需要轉(zhuǎn)換。
如何將datatable轉(zhuǎn)成實(shí)體對(duì)象?主要思想是將datatable中的屬性逐個(gè)取出,放入學(xué)生成員中。例如,datatabledt;(數(shù)據(jù)已經(jīng)在其中)arraylistrestudentlist;For(inti=0I)<dt.ROWS.COUNT行數(shù);i){Studentst=newStudent()dt.行[i][“studentId”]=圣學(xué)生;。。。。。retStudentList.add文件結(jié)果在retstudentlist中。。。
怎么解析Object對(duì)象里面放的數(shù)據(jù)集轉(zhuǎn)換成dataTable-CSDN論壇?Publicstaticdatatabletodatatable
{
//創(chuàng)建屬性集合
list
type=typeof(tresult)
datatableDT=newdatatable()數(shù)組.ForEach
Foreach(VaRiteminvalue)
{
//創(chuàng)建一個(gè)DataRow實(shí)例
DataRowrow=紐羅醫(yī)生
普利斯特福雷奇(p=>行[p.Name]=p、GetValue(item,null))數(shù)據(jù)行添加(row)
}
returndt
}
類{publicinta{getset}publicinta{getset}}B類:a{publicintb{GetSet}publicintbb{GetSet}//邏輯測(cè)試類classtest{publicvoid(){listlist=newlist()//轉(zhuǎn)換對(duì)象variant=fromlistselectnew{Itema=C.A,itemaa=C.aa,itemb=C.B,項(xiàng)B=C.bb}
分享標(biāo)題:datatable獲取列數(shù)據(jù)如何將DataTable轉(zhuǎn)換為list?-創(chuàng)新互聯(lián)
標(biāo)題URL:http://aaarwkj.com/article4/ccjpoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、外貿(mào)網(wǎng)站建設(shè)、商城網(wǎng)站、ChatGPT、域名注冊(cè)、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容