dataGrid转换dataTable

#region dataGrid转换dataTable
   /// <summary>
   /// dataGrid转换dataTable
   /// </summary>
   /// <param name="dg">dataGrid</param>
   /// <returns>返回dataTable</returns>
   public DataTable DT(DataGrid dg)
   {
    try
    {
     DataTable dt = null;  
       
     if(dg.DataSource is DataView)  
     {  
      dt = (dg.DataSource as DataView).Table;  
     }  
     else if(dg.DataSource is DataTable)  
     {  
      dt = dg.DataSource as DataTable;  
     }  
     else if(dg.DataSource is DataSet)  
     {  
      dt = (dg.DataSource as DataSet).Tables[0]; 
     }
     return dt;
    }
    catch (System.Exception ex)
    {
     throw ex;
    }
   }
   #endregion

时间: 2024-08-07 13:02:17

dataGrid转换dataTable的相关文章

服务器不装Excel读取Excel并转换DataTable

原来是用OleDb.4.0组件读取Excel,但是放到服务器后 傻了,服务器没装Excel ,而且领导说不可以装 没办法,只好自己重新找下代码 在CodeProject找到一个开源的dll,一阵欢喜啊,虽然是winform项目,但是主要是用他的类库所以提取一下后 自己研究后重新封装了一个类,运行 耶! 完美支持 需要Dome的同学下载后去研究下吧 地址:http://download.csdn.net/detail/jine515073/7266371 本人用 Excel 97-2003 工作表

List转换DataTable

/// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list">泛类型集合</param> /// <returns></returns> public static DataTable ListToDataTable<T>(List<T> entitys) { //检查实体集合不能为空 if (

DataRow[]转换DataTable

public DataTable ToDataTable(DataRow[] rows)    {        if (rows == null || rows.Length == 0) return null;        DataTable tmp = rows[0].Table.Clone();  // 复制DataRow的表结构        foreach (DataRow row in rows)            tmp.Rows.Add(row);  // 将DataRo

DataRow数组转换DataTable

public DataTable ToDataTable(DataRow[] rows) { if (rows == null || rows.Length == 0) return null; DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构 foreach (DataRow row in rows) tmp.Rows.Add(row.ItemArray); // 将DataRow添加到DataTable中 return tmp;

DataRow[] /数组转换datatable!

/// <summary> /// /// </summary> /// <param name="dt"></param> /// <param name="strWhere">筛选的条件</param> /// <returns></returns> public DataTable SreeenDataTable(DataTable dt,string strWhe

List&lt;T&gt; 转换 DataTable

public class List2DataTable     { public static string GetClassName(Type type) {             if (type == null) throw new ArgumentException("参数type不能为空"); if (type.HasAttribute<AliasAttribute>()) return type.GetAttribute<AliasAttribute&g

把datagrid转换成gridview

public gridview datagrid2gridview(datagrid dg) { gridview gv = new gridview(); foreach(var p in dg.columns) { if(p is boundcolumn) { boundcolumn dgc = (boundcolumn)p; var gvc=new boundfield(); gvc.headertext=dgc.headertext; gvc.visible=dgc.visible; g

读CSV转换datatable

using System.Data; using System.IO; /// <summary> /// Stream读取.csv文件 /// </summary> /// <param name="filePath">文件路径</param> /// <returns></returns> public static DataTable OpenCSV(string filePath) {     DataTa

SqL读取XML、解析XML、SqL将XML转换DataTable、SqL将XML转换表

DECLARE @ItemMessage XML DECLARE @ItemTable TABLE(ItemNumber INT PRIMARY KEY,ItemDescription NVARCHAR(300)) SET @ItemMessage=N' <ReceivablesInfos> <ReceivablesList> <LIFNR>0000xxxxxx</LIFNR> <NAME1>上海有限公司</NAME1> <BU