protected MTable getTableByRC(int[] rows, string[] selectCols) { MTable ret = new MTable(); for (int i = 0; i < selectCols.Length; i++) { if (!this.Table.Columns.Contains(selectCols[i])) { throw (new Exception("不存在该列!")); } ret.Table.Columns.Add(selectCols[i], this.Table.Columns[selectCols[i]].DataType); } if (this.tTable == null) { return(null); } for (int i = 0; i < rows.Length; i++) { if (i >= this.Table.Rows.Count) { throw new Exception("选出的行号越界!"); } DataRow dr = ret.tTable.NewRow(); for (int j = 0; j < selectCols.Length; j++) { dr[selectCols[j]] = this.Table.Rows[i][selectCols[j]]; } ret.Table.Rows.Add(dr); } return(ret); }
public BaseDataTable(MTable tb) { if (tb == null || tb.GetTable() == null) { throw (new Exception("数据异常!")); } this.Table = tb.GetTable().Copy(); }
public void Contact(MTable tb) { for (int i = 0; i < tb.Count; i++) { DataRow dr = this.Table.NewRow(); dr.ItemArray = tb.Table.Rows[i].ItemArray; } }
public List <T> ToList <T>(string rows, string colname) { if (rows == null || rows.Trim().Length == 0 || rows.Trim() == "*" || rows.Trim() == ":") { return(ToList <T>(colname)); } MTable ret = this[rows, colname]; return(ret.ToList <T>(colname)); }
protected MTable getCrossTable(List <int> SelectRows, string SelectCols) { MTable ret = null; string[] ColArr = SelectCols.Trim().Split(','); if (SelectCols.Trim() == "*") { ColArr = this.TColumns.Keys.ToArray <string>(); } ret = getTableByRC(SelectRows.ToArray <int>(), ColArr); return(ret); }
public void Union(MTable tb) { if (tb.Count > 0 && this.Count > 0 && tb.Count != this.Count) { throw (new Exception("联合的表行数需要一致!")); } for (int i = 0; i < tb.GetTable().Columns.Count; i++) { DataColumn dc = tb.GetTable().Columns[i]; if (!this.Table.Columns.Contains(dc.ColumnName)) { Type t = dc.DataType; this.AddColumnByArray(dc.ColumnName, tb, dc.ColumnName); } } }
public MTable Select(string sql) { if (this.Table == null) { return(null); } MTable ret = new MTable(); ret.Table = this.Table.Clone(); if (sql == null || sql.Trim().Length == 0) { return(ret); } DataRow[] drs = this.Table.Select(sql); for (long i = 0; i < drs.Length; i++) { DataRow dr = ret.Table.NewRow(); dr.ItemArray = drs[i].ItemArray; ret.Table.Rows.Add(drs[i].ItemArray); } return(ret); }
public void AddColumnByArray(string ColumnName, MTable tb, string col) { Type t = tb.GetTable().Columns[col].DataType; if (Table == null) { Table = new DataTable(); } if (this.Count > 0 && tb.Count > 0 && this.Count != tb.Count) { throw (new Exception("插入新列元素数量与现有元素数量不匹配!")); } if (!this.Table.Columns.Contains(ColumnName)) { this.Table.Columns.Add(ColumnName, t); } DataTable dt = tb.GetTable(); for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = null; if (i < this.Table.Rows.Count) { dr = this.Table.Rows[i]; } if (dr == null) { dr = this.Table.NewRow(); this.Table.Rows.Add(dr); } if (dt.Rows[i].IsNull(col)) { continue; } dr[ColumnName] = Convert.ChangeType(dt.Rows[i][col], t); } }