我有一个应该返回2行的sql语句。先用psychological_id = 1,和第二,psychological_id = 2这里是SQL语句sql语句应该有2个不同的行,但只返回1
select * from psychological where patient_id = 12 and symptom = 'delire';
但是与此代码,利用该予填充什么被认为是2个不同的行的阵列列表中,两个行存在,但具有相同的值:第二行。
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());
消息框输出“2”,而它应该输出“1”。有人知道发生了什么事?
但不是应该在oneSympAll arraylist中有2个不同的oneSymps吗?我的意思是,第一次,oneSymp的一个版本被添加到数组列表中,第二次,一个不同的版本。他们应该不一样吗? – jello 2010-03-14 04:03:11
@jello:不,你添加了两次相同的参考。 – 2010-03-14 04:11:16