首页 > 代码库 > DataTable表的遍历

DataTable表的遍历

1、        

    for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    sb.Append(dt.Rows[i][j] + "   ");
                }
                sb.AppendLine();
            }

2、
            foreach (DataRow row in dt.Rows)
            {
                foreach (DataColumn c in dt.Columns)
                {
                    sb.Append(row[c.ColumnName] + "   ");
                }
                sb.AppendLine();
            }

3、
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 0; j < dt.Rows[i].ItemArray.Length; j++)
                {
                    sb.Append(dt.Rows[i][j] + "   ");
                }
            }

DataTable表的遍历