码迷,mamicode.com
首页 > Windows程序 > 详细

.Net常用技巧_将DataGridView的内容转换成DataTable

时间:2014-07-16 23:13:43      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:datagridview   style   blog   color   os   io   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Utility;

namespace MyTool
{
    public class GetDgvToTable
    {
        public static DataTable GetTable(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] = Convert.ToString(dgv.Rows[count].Cells[countsub].Value);
                }
                dt.Rows.Add(dr);
            } return dt;
        }


    }
}

 

.Net常用技巧_将DataGridView的内容转换成DataTable,布布扣,bubuko.com

.Net常用技巧_将DataGridView的内容转换成DataTable

标签:datagridview   style   blog   color   os   io   

原文地址:http://www.cnblogs.com/yuyuanfeng/p/3811501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!