C 集合轉換為DataTable

2022-02-25 13:42:31 字數 3982 閱讀 1959

該類就用了幾個型別,如int,int?,string,所以其它型別就先沒管。

用到的類:

public

class

tb_projects

public

string projectname

//////

編碼

/// public

string projectcode

public

int parentid

public

int? nextid

public

int? projectorder

public

int isenabled

//////

業主單位id

/// public

int? ownerid

//////

施工單位id

/// public

int? constructionid

//////

監理單位id

/// public

int? supervisionid

//////

承包單位id

/// public

int? contractid

//////

第幾級(即在樹層次中第幾級,根元素級次為1,以此類推)

/// public

int? level

//////

數量

/// public

int? quantity

public

int versioning

//////

里程樁號

/// public

string mileageno

//////

標準編碼

/// public

string componentcode

//////

內部編碼

/// public

string ncomponentcode

//////

流程狀態

/// public

int taskstatus

public

string fbxid

//////

判斷是否為單位工程

/// public

int issubunit

//////

所屬標段

/// public

string bidsion

}

view code

**1:

stringbuilder sb = new

stringbuilder();

type elementtype = typeof

(models.tb_projects);

elementtype.getproperties().tolist().foreach(propinfo =>))\"]=item.;}}\r\n

"); }

else

"row[\"\"]=item.;\r\n

"); }

}else

))\"]=item.;}}\r\n

"); }

else

"if(item.!=null)\"]=item.;}}\r\n

"); }

}});

system.io.file.writealltext(

"2.txt

", sb.tostring());

console.readline();

**2:

public datatable getdatatable(listlist)

//else

//

//});

"2.txt", sb.tostring());

//row["proid"] = item.proid;

//row["projectname"] = item.projectname;

//row["parentid"] = item.parentid;

//row["level"] = item.level;

//row["bidsion"] = item.bidsion;

//row["versioning"] = item.versioning;

//row["mileageno"] = item.mileageno;

//row["projectorder"] = item.projectorder;

//row["projectcode"] = item.projectcode;

//row["ncomponentcode"] = item.ncomponentcode;

//row["nextid"] = 0;

//row["isenabled"] = 0;

#endregion

//預設值 賦空

elementtype.getproperties().tolist().foreach(propinfo => row[propinfo.name] =dbnull.value);

//不為空 賦值

row["

proid

"] =item.proid;

if (!string.isnullorwhitespace(item.projectname))

if (!string.isnullorwhitespace(item.projectcode))

row[

"parentid

"] =item.parentid;

if (item.nextid != null)

if (item.projectorder != null)

row[

"isenabled

"] =item.isenabled;

if (item.ownerid != null)

if (item.constructionid != null)

if (item.supervisionid != null)

if (item.contractid != null)

if (item.level != null)

if (item.quantity != null)

row[

"versioning

"] =item.versioning;

if (!string.isnullorwhitespace(item.mileageno))

if (!string.isnullorwhitespace(item.componentcode))

if (!string.isnullorwhitespace(item.ncomponentcode))

row[

"taskstatus

"] =item.taskstatus;

if (!string.isnullorwhitespace(item.fbxid))

row[

"issubunit

"] =item.issubunit;

if (!string.isnullorwhitespace(item.bidsion))

//初值 僅這裡使用

row["

nextid

"] = 0

; row[

"isenabled

"] = 0

; dt.rows.add(row);

});return

dt; }

C 集合轉換為DataTable

該類就用了幾個型別,如int,int?string,所以其它型別就先沒管。用到的類 public class tb projects public string projectname 編碼 public string projectcode public int parentid public i...

DataTable 轉換為 List 集合

今天原本想從本地資料庫裡面讀取資料,學習一下linq的語法,想不到把資料讀取出來後竟然在想怎麼把它轉換為list集合,其實我用的是泛型,但是,我只需要資料,所以就直接list。也許是自己太久沒接觸c 了,都有點生疏,覺得可以實現 但不能說好吧 轉換 如下 public listconnectsql ...

把DataTable轉換為List

前一篇有學習過 把list轉換為datatable 那此篇,將是學習反向,把datatable轉換為list。這個方法使用的較多。很多情況之後,從資料讀出來的資料是dataset或是datatable。需要把它們轉換為list之後,再轉換為json。下面insus.net寫乙個擴充套件方法 接下來,...