sql语句如下:
SELECT DISTINCT organization_name, (SELECT C FROM [教基1001] as x where x.A = 18 AND a.organization_no = x.organization_no) as contact
,(SELECT C FROM [教基1001] as y where y.A = 19 AND a.organization_no = y.organization_no) as contactduty
FROM [教基1001] as a
ORDER BY gather_organization_no, organization_no;
在数据库中结果是正常的:
使用该sql语句的代码如下:
string sqlStr = string.Format(@"SELECT DISTINCT organization_name, (SELECT C FROM [教基1001] as x where x.A = 18 AND a.organization_no = x.organization_no) as contact
,(SELECT C FROM [教基1001] as y where y.A = 19 AND a.organization_no = y.organization_no) as contactduty
FROM [教基1001] as a
ORDER BY gather_organization_no, organization_no;");
List<DuDaoSchool> lists = new List<DuDaoSchool>();
if (con.State == ConnectionState.Closed)
{
con.Open();
SQLiteCommand com = new SQLiteCommand
{
Connection = this.con,
CommandText = sqlStr,
CommandTimeout = 60 * 20,
CommandType = CommandType.Text
};
SQLiteDataReader rdr = com.ExecuteReader();
while (rdr.Read())
{
DuDaoSchool entity = new DuDaoSchool
{
Name = rdr["organization_name"].ToString(),
Contact = rdr["contact"].ToString(),
ContactDuty = rdr["contactduty"].ToString()
};
lists.Add(entity);
}
}
但是运行的结果,除了organization_name是正常的,另外两列都变成0了:
请问这是什么原因?问题出在哪?