MySql Query和asp.net c#之间的结果差异

时间:2016-02-13 22:24:25

标签: mysql asp.net

我有一个MySql命令,如下所示:

    string listfh = "Select class_id, location_nm, b.ref_desc, c.ref_desc ,a.days From fh_info as a LEFT JOIN (ref_section as b, ref_language as c) ON  ((a.section_id=b.cd) and (a.language_id = c.cd)) WHERE year(a.fh_dt) = '2015' And region_id like 'B%' Order by fh_dt desc";
    MySqlDataAdapter daFt = new MySqlDataAdapter(listfh, conn);
    daFt.Fill(dtList);

结果返回null。但是当在Navicat Query中运行相同的命令时,它会返回正确的答案(2行)。怎么了?

1 个答案:

答案 0 :(得分:0)

检查你的connectionString(conn)是否正确指向你的数据库,并在你的表/视图名称之前提到你的数据库名称,以便与数据库对象建立正确的连接,如:

    string listfh = "Select class_id, location_nm, b.ref_desc, c.ref_desc ,a.days From DatabaseName.dbo.fh_info as a LEFT JOIN (DataBaseName.dbo.ref_section as b, DatabaseName.dbo.ref_language as c) ON  ((a.section_id=b.cd) and (a.language_id = c.cd)) WHERE year(a.fh_dt) = '2015' And region_id like 'B%' Order by fh_dt desc";
    MySqlDataAdapter daFt = new MySqlDataAdapter(listfh, conn);
    daFt.Fill(dtList);