public static List<Peak> GetPeaksByScanId(int scanId) { List<Peak> result = new List<Peak>(); using (OleDbConnection conn = CreateConnection(GlobalConfigVars.DbPath)) { using (var cmd = new OleDbCommand()) { cmd.Connection = conn; cmd.CommandText = "select * from Peak where ScanIdNr = @scanId"; cmd.Parameters.AddWithValue("@scanId", scanId); if (conn.State == ConnectionState.Closed) conn.Open(); var reader = cmd.ExecuteReader(); using (reader) { while (reader.Read()) { //Peak p = new Peak //{ // Index = reader.GetInt16(reader.GetOrdinal("Index")), // Left = reader.GetInt32(reader.GetOrdinal("Left")), // Top = reader.GetInt32(reader.GetOrdinal("Top")), // Right = reader.GetInt32(reader.GetOrdinal("Right")), // Name = reader.GetString(reader.GetOrdinal("Name")), // MSpike = 1==reader.GetByte(reader.GetOrdinal("MSpike")) //}; Peak p = new Peak { Index = reader.GetInt16(reader.GetOrdinal("Index")), Left = reader.GetInt32(reader.GetOrdinal("Left")), Top = reader.GetInt32(reader.GetOrdinal("Top")), Right = reader.GetInt32(reader.GetOrdinal("Right")), MSpike = 1 == reader.GetByte(reader.GetOrdinal("MSpike")) }; // 名称可能为空 try { p.Name = reader.GetString(reader.GetOrdinal("Name")); } catch(Exception ex) { } result.Add(p); } } } } return result; }