本文共 465 字,大约阅读时间需要 1 分钟。
通过通用类,返回一个DataTable,要想显示每个单元格,只要做两次循环即可:
foreach (DataRow row in dt.Rows) { foreach (DataColumn column in dt.Columns) { Console.WriteLine(row[column]); } }
row[column] 中的column是检索出来的表个列名。
如果想把某列的值拼接字符串,那就去掉内层循环就行了:
StringBuilder mailList = new StringBuilder();foreach (DataRow row in dt.Rows){ mailList.Append(row["Email"]); mailList.Append(";");}
转载地址:http://chzvi.baihongyu.com/