/// <summary>
        /// 把DataTable填充到数据容器中,方便填充数据到DataWindow
        /// </summary>
        /// <param name="dataTable">数据容器</param>
        /// <param name="dt">DataTable</param>
        /// <Author>jianghaoqun 2007-06-07</Author>
        public static void Fill(LiteDataTable dataTable, DataTable dt)
        {
            int columnsCount = dataTable.Columns.Count;
            if (columnsCount == 0)
            {
                columnsCount = dt.Columns.Count;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    dataTable.Columns.Add(new LiteDataColumn(dt.Columns[i].ColumnName, dt.Columns[i].DataType));
                }
            }

            foreach (DataRow dr in dt.Rows)
            {
                var row = dataTable.NewRow();
                for (int i = 0; i < columnsCount; i++)
                {
                    var value = dr[i];
                    if (value != DBNull.Value)
                    {
                        row[i] = value;
                    }
                }
                dataTable.Rows.Add(row);
            }
        }
        /// <summary>
        /// 把DataTable填充到数据容器中,方便填充数据到DataWindow
        /// </summary>
        /// <param name="dataTable">数据容器</param>
        /// <param name="dt">DataTable</param>
        /// <Author>jianghaoqun 2007-06-07</Author>
        public static void Fill(LiteDataTable dataTable, DataTable dt)
        {
            int columnsCount = dataTable.Columns.Count;

            if (columnsCount == 0)
            {
                columnsCount = dt.Columns.Count;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    dataTable.Columns.Add(new LiteDataColumn(dt.Columns[i].ColumnName, dt.Columns[i].DataType));
                }
            }

            foreach (DataRow dr in dt.Rows)
            {
                var row = dataTable.NewRow();
                for (int i = 0; i < columnsCount; i++)
                {
                    var value = dr[i];
                    if (value != DBNull.Value)
                    {
                        row[i] = value;
                    }
                }
                dataTable.Rows.Add(row);
            }
        }
        /// <summary>
        /// 使用 IDataReader 中的结构为指定的表格添加列。
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="reader"></param>
        public static void AddColumns(LiteDataTable dataTable, IDataReader reader)
        {
            //columnsCount = reader.FieldCount;

            var schema = reader.GetSchemaTable();
            foreach (DataRow dr in schema.Rows)
            {
                dataTable.Columns.Add(new LiteDataColumn(dr["ColumnName"].ToString(), dr["DataType"].ToString()));
            }
        }
Example #4
0
        private static LiteDataTable ConvertToLiteDataTable(IDataReader reader)
        {
            var table = new LiteDataTable();

            using (reader)
            {
                LiteDataTableAdapter.Fill(table, reader);
            }
            return(table);
        }
        /// <summary>
        /// 使用 IDataReader 中的结构为指定的表格添加列。
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="reader"></param>
        public static void AddColumns(LiteDataTable dataTable, IDataReader reader)
        {
            //columnsCount = reader.FieldCount;

            var schema = reader.GetSchemaTable();

            foreach (DataRow dr in schema.Rows)
            {
                dataTable.Columns.Add(new LiteDataColumn(dr["ColumnName"].ToString(), dr["DataType"].ToString()));
            }
        }
        /// <summary>
        /// 根据SQL Command返回的IDataReader填充数据容器
        /// <para>
        /// 对于DBNull的值,填充null
        /// </para>
        /// </summary>
        /// <param name="dataTable">数据容器</param>
        /// <param name="reader">SQL语句返回的</param>
        public static void Fill(LiteDataTable dataTable, IDataReader reader)
        {
            if (dataTable.Columns.Count == 0)
            {
                AddColumns(dataTable, reader);
            }

            int columnsCount = dataTable.Columns.Count;

            while (reader.Read())
            {
                var row = dataTable.NewRow();
                for (int i = 0; i < columnsCount; i++)
                {
                    var value = reader[i];
                    if (value != DBNull.Value)
                    {
                        row[i] = value;
                    }
                }
                dataTable.Rows.Add(row);
            }
        }
        /// <summary>
        /// 根据SQL Command返回的IDataReader填充数据容器
        /// <para>
        /// 对于DBNull的值,填充null
        /// </para>
        /// </summary>
        /// <param name="dataTable">数据容器</param>
        /// <param name="reader">SQL语句返回的</param>
        public static void Fill(LiteDataTable dataTable, IDataReader reader)
        {
            if (dataTable.Columns.Count == 0)
            {
                AddColumns(dataTable, reader);
            }

            int columnsCount = dataTable.Columns.Count;

            while (reader.Read())
            {
                var row = dataTable.NewRow();
                for (int i = 0; i < columnsCount; i++)
                {
                    var value = reader[i];
                    if (value != DBNull.Value)
                    {
                        row[i] = value;
                    }
                }
                dataTable.Rows.Add(row);
            }
        }
Example #8
0
 internal LiteDataRow(LiteDataTable table)
 {
     _table = table;
     _values = new object[_table.Columns.Count];
 }
Example #9
0
 private static LiteDataTable ConvertToLiteDataTable(IDataReader reader)
 {
     var table = new LiteDataTable();
     using (reader)
     {
         LiteDataTableAdapter.Fill(table, reader);
     }
     return table;
 }
Example #10
0
 internal LiteDataRow(LiteDataTable table)
 {
     _table  = table;
     _values = new object[_table.Columns.Count];
 }