我有一个如下的MySql命令:
string listfh =“选择class_id,location_nm,b.ref_desc,c.ref_desc,a.days从fh_info作为左联接(ref_section为b,ref_language为c)ON((a.section_id = b.cd)和(a。 language_id = c.cd))WHERE year(a.fh_dt)='2015'and region_id如'B%'由fh_dt desc排序”;
MySqlDataAdapter daFt =新的MySqlDataAdapter(listfh,conn);
daFt.Fill(dtList);
结果返回null。但是,当在Navicat Query中运行相同的命令时,它将返回正确的答案(2行)。怎么了
最佳答案
检查您的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);
关于mysql - MySql查询和asp.net C#之间的结果差异,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35386044/