/// <summary> /// 强制转换GridView的数据为DataTable /// </summary> /// <param name="dgv">需换换的GridView</param> /// <returns>返回DataTable</returns> public DataTable GetDgvToTable(DataGridView dgv) { DataTable dt = new DataTable(); for (int count = 0; count < dgv.Columns.Count; count++) { DataColumn dc = new DataColumn(dgv.Columns[count].Name.ToString()); dt.Columns.Add(dc); } for (int count = 0; count < dgv.Rows.Count; count++) { DataRow dr = dt.NewRow(); for (int countsub = 0; countsub < dgv.Columns.Count; countsub++) { dr[countsub] = dgv.Rows[count].Cells[countsub].Value; } dt.Rows.Add(dr); } return dt; }
C# 强制转换GridView的数据为DataTable,布布扣,bubuko.com
原文:http://www.cnblogs.com/axiaostudio/p/3691985.html