public static Demographic GetDemographicById(int id) { using (OleDbConnection conn = CreateConnection(GlobalConfigVars.DbPath)) { using (var cmd = new OleDbCommand()) { cmd.Connection = conn; cmd.CommandText = "select * from Demographic where DemographicIdNr = @id"; cmd.Parameters.AddWithValue("@id", id); if (conn.State == ConnectionState.Closed) { conn.Open(); } var reader = cmd.ExecuteReader(); using (reader) { if (reader.Read()) { Demographic result = new Demographic(); int defId = reader.GetInt32(1); result.Def = GetDemoDefById(defId); for (int i = 2; i < result.Def.NumberOfFields + 2; i++) { string v = DBNull.Value == reader[i] ? "" : reader.GetString(i); result.SetValue(i-2, (string) v); } return result; } } } } return null; }
public static Demographic GetDemographicById(int id) { using (OleDbConnection conn = CreateConnection(GlobalConfigVars.DbPath)) { using (var cmd = new OleDbCommand()) { cmd.Connection = conn; cmd.CommandText = "select * from Demographic where DemographicIdNr = @id"; cmd.Parameters.AddWithValue("@id", id); if (conn.State == ConnectionState.Closed) { conn.Open(); } var reader = cmd.ExecuteReader(); using (reader) { if (reader.Read()) { Demographic result = new Demographic(); int defId = reader.GetInt32(1); result.Def = GetDemoDefById(defId); for (int i = 2; i < result.Def.NumberOfFields + 2; i++) { string v = DBNull.Value == reader[i] ? "" : reader.GetString(i); result.SetValue(i - 2, (string)v); } return(result); } } } } return(null); }