/// <summary> /// Fill /// </summary> /// <param name="ds"></param> public void Fill(DataSet ds) { if (ds == null) { ds = new DataSet(); } using (KdbndpDataReader dr = command.ExecuteReader()) { do { var dt = new DataTable(); var columns = dt.Columns; var rows = dt.Rows; for (int i = 0; i < dr.FieldCount; i++) { string name = dr.GetName(i).Trim(); if (!columns.Contains(name)) { columns.Add(new DataColumn(name, dr.GetFieldType(i))); } } while (dr.Read()) { DataRow daRow = dt.NewRow(); for (int i = 0; i < columns.Count; i++) { daRow[columns[i].ColumnName] = dr.GetValue(i); } dt.Rows.Add(daRow); } ds.Tables.Add(dt); } while (dr.NextResult()); } }
/// <summary> /// Fill /// </summary> /// <param name="dt"></param> public void Fill(DataTable dt) { if (dt == null) { dt = new DataTable(); } var columns = dt.Columns; var rows = dt.Rows; using (KdbndpDataReader dr = command.ExecuteReader()) { for (int i = 0; i < dr.FieldCount; i++) { string name = dr.GetName(i).Trim(); if (!columns.Contains(name)) { columns.Add(new DataColumn(name, dr.GetFieldType(i))); } else { columns.Add(new DataColumn(name + i, dr.GetFieldType(i))); } } while (dr.Read()) { DataRow daRow = dt.NewRow(); for (int i = 0; i < columns.Count; i++) { daRow[columns[i].ColumnName] = dr.GetValue(i); } dt.Rows.Add(daRow); } } dt.AcceptChanges(); }