我有一个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行)。怎么了?
答案 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);