日期:2014-05-17  浏览次数:21352 次

关于asp.net操作oracle数据库的问题
SQL code
 
select c.cod_mitem,b.rot_ord,b.Plan_wkhr_m,(sum(a.plan_wkhr_n) + sum(a.plan_wkhr_o))from web_wlms_o4sequence_user a
      left join web_wlms_o3sequence b on a.rot_ord_id = b.id
      left join web_wlms_o2order c on b.num_ord_id = c.id
      group by c.cod_mitem,b.rot_ord,b.Plan_wkhr_m order by rot_ord

上述代码加载进gridview的时候为什么会出错
Bll代码
C# code

public static DataTable GetAll()
{
   string sql = "select c.cod_mitem,b.rot_ord,b.Plan_wkhr_m,sum(a.plan_wkhr_n) from web_wlms_o4sequence_user a";
   sql = sql + string.Format("left join web_wlms_o3sequence b on a.rot_ord_id = b.id");
   sql = sql + string.Format("left join web_wlms_o2order c on b.num_ord_id = c.id");
   sql = sql + string.Format("where a.status ='01' group by c.cod_mitem,b.rot_ord,b.Plan_wkhr_m order by rot_ord");
   //string sql = "select user_id,user_nm,adr_r from web_user";
   DataTable dt = QueryHelper.QueryDataTable(sql);
   return dt;
}


gridview就是显示不出来
但是换成是注释行代码就没问题
如果执行的是//string sql = "select user_id,user_nm,adr_r from web_user";
那么gridview里面绑定的就是user_id,user_nm,adr_r
问一下,如果执行未注释行代码,gridview里应该绑定对于的是什么~

------解决方案--------------------
绑定的就是你select出来的所有列

还有一点,你在拼接SQL的时候,一定注意空格分割,要不然就会语法错误
应该如下
C# code
string sql = "select c.cod_mitem,b.rot_ord,b.Plan_wkhr_m,sum(a.plan_wkhr_n) from web_wlms_o4sequence_user a ";
                sql = sql + string.Format(" left join web_wlms_o3sequence b on a.rot_ord_id = b.id ");
                sql = sql + string.Format(" left join web_wlms_o2order c on b.num_ord_id = c.id ");