private static DemoDef GetDemoDefById(int defId) { using (OleDbConnection conn = CreateConnection(GlobalConfigVars.DbPath)) { using (var cmd = new OleDbCommand()) { cmd.Connection = conn; cmd.CommandText = "select * from DemoDef where DemoDefIdNr = @id"; cmd.Parameters.AddWithValue("@id", defId); if (conn.State == ConnectionState.Closed) { conn.Open(); } var reader = cmd.ExecuteReader(); using (reader) { if (reader.Read()) { DemoDef result = new DemoDef { NumberOfFields = reader.GetInt16(1) }; for (int i = 2; i < result.NumberOfFields * 2 + 2; i += 2) { result.AddField(new FieldDef { FieldType = reader.GetByte(i), Field = reader.GetString(i + 1) }); } return result; } } } } return null; }
private static DemoDef GetDemoDefById(int defId) { using (OleDbConnection conn = CreateConnection(GlobalConfigVars.DbPath)) { using (var cmd = new OleDbCommand()) { cmd.Connection = conn; cmd.CommandText = "select * from DemoDef where DemoDefIdNr = @id"; cmd.Parameters.AddWithValue("@id", defId); if (conn.State == ConnectionState.Closed) { conn.Open(); } var reader = cmd.ExecuteReader(); using (reader) { if (reader.Read()) { DemoDef result = new DemoDef { NumberOfFields = reader.GetInt16(1) }; for (int i = 2; i < result.NumberOfFields * 2 + 2; i += 2) { result.AddField(new FieldDef { FieldType = reader.GetByte(i), Field = reader.GetString(i + 1) }); } return(result); } } } } return(null); }