public WayDataSet SelectDataSet(string sql, params object[] parames) { bool needToClose = false; if (this.Connection.State != System.Data.ConnectionState.Open) { needToClose = true; this.Connection.Open(); } try { using (var command = this.CreateCommand(sql, parames)) { var dataset = new WayDataSet(); using (var datareader = command.ExecuteReader()) { do { if (datareader.HasRows) { var datatable = new WayDataTable(); for (int i = 0; i < datareader.FieldCount; i++) { string name = datareader.GetName(i); datatable.Columns.Add(new WayDataColumn(name, datareader.GetFieldType(i).FullName)); } dataset.Tables.Add(datatable); while (datareader.Read()) { var row = new WayDataRow(); datatable.Rows.Add(row); for (int i = 0; i < datareader.FieldCount; i++) { string name = datareader.GetName(i); row[name] = datareader[i]; } } } }while (datareader.NextResult()); } return(dataset); } } catch { throw; } finally { if (needToClose) { this.Connection.Close(); } } }
public WayDataTable SelectTable(string sql, params object[] parames) { bool needToClose = false; if (this.Connection.State != System.Data.ConnectionState.Open) { needToClose = true; this.Connection.Open(); } try { using (var command = this.CreateCommand(sql, parames)) { var dtable = new WayDataTable(); using (var reader = command.ExecuteReader()) { for (int i = 0; i < reader.FieldCount; i++) { string name = reader.GetName(i); dtable.Columns.Add(new WayDataColumn(name, reader.GetFieldType(i).FullName)); } while (reader.Read()) { var row = new WayDataRow(); dtable.Rows.Add(row); for (int i = 0; i < reader.FieldCount; i++) { string name = reader.GetName(i); row[name] = reader[i]; if (reader[i] != null) { string typename = reader.GetFieldType(i).FullName; if (typename != dtable.Columns[i].DataType) { dtable.Columns[i].DataType = typename; } } } } } return(dtable); } } catch { throw; } finally { if (needToClose) { this.Connection.Close(); } } }
public WayDataTable(System.Data.DataTable source) : this() { this.Rows.Clear(); this.TableName = source.TableName; foreach (System.Data.DataColumn column in source.Columns) { this.Columns.Add(new WayDataColumn(column.ColumnName, column.DataType.FullName)); } foreach (System.Data.DataRow row in source.Rows) { var newrow = new WayDataRow(); this.Rows.Add(newrow); newrow.RowState = (DataRowState)row.RowState; foreach (System.Data.DataColumn column in source.Columns) { newrow[column.ColumnName] = row[column.ColumnName]; } } }