It's been helpfully suggested that I don't have to keep writing
dr["building_id"].ToString()
in the code snipped below. That I only need to put the above into a variable, i.e, sBldgID, and use the latter subsequently.
...
using (OracleCommand cmd = new OracleCommand(sql, conn)) {
cmd.CommandType = CommandType.Text;
using (OracleDataReader dr = cmd.ExecuteReader()) {
while (dr.Read()) {
if (dr["building_id"].ToString() != " " && dr["building_id"].ToString() != "" && dr["building_id"].ToString() != null) {
using (SpreadsheetDocument document = SpreadsheetDocument.Open(path, true)) {
IEnumerable<Sheet> sheets = document.WorkbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == dr["building_id"].ToString());
WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.FirstOrDefault().Id);
...
}
}
}
}
}
...
Good advice. How do I do it? How do I use dr.Read() that way before the while loop starts? Thanks.