sql statement supposed to have 2 distinct rows, but only 1 is returned. for C# windows

Posted by jello on Stack Overflow See other posts from Stack Overflow or by jello
Published on 2010-03-14T03:52:19Z Indexed on 2010/03/14 3:55 UTC
Read the original article Hit count: 304

Filed under:
|

yeah so I have an sql statement that is supposed to return 2 rows. the first with psychological_id = 1, and the second, psychological_id = 2. here is the sql statement

select * from psychological where patient_id = 12 and symptom = 'delire';

But with this code, with which I populate an array list with what is supposed to be 2 different rows, two rows exist, but with the same values: the second row.

OneSymptomClass oneSymp = new OneSymptomClass();
        ArrayList oneSympAll = new ArrayList();

        string connStrArrayList = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\PatientMonitoringDatabase.mdf; " +
            "Initial Catalog=PatientMonitoringDatabase; " +
            "Integrated Security=True";

        string queryStrArrayList = "select * from psychological where patient_id = " + patientID.patient_id + " and symptom = '" + SymptomComboBoxes[tag].SelectedItem + "';";

        using (var conn = new SqlConnection(connStrArrayList))
        using (var cmd = new SqlCommand(queryStrArrayList, conn))
        {
            conn.Open();

            using (SqlDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    oneSymp.psychological_id = Convert.ToInt32(rdr["psychological_id"]);
                    oneSymp.patient_history_date_psy = (DateTime)rdr["patient_history_date_psy"];
                    oneSymp.strength = Convert.ToInt32(rdr["strength"]);
                    oneSymp.psy_start_date = (DateTime)rdr["psy_start_date"];
                    oneSymp.psy_end_date = (DateTime)rdr["psy_end_date"];

                    oneSympAll.Add(oneSymp);
                }
            }

            conn.Close();
        }

        OneSymptomClass testSymp = oneSympAll[0] as OneSymptomClass;
        MessageBox.Show(testSymp.psychological_id.ToString());

the message box outputs "2", while it's supposed to output "1". anyone got an idea what's going on?

© Stack Overflow or respective owner

Related posts about sql

Related posts about arraylist