问题描述
附上数据库查询结果PublicClassForm1DimconnAsOracleConnection=NewOracleConnection()DimdaAsNewOracleDataAdapter()DimsqlAsStringDimcmd,cmd1AsNewOracleCommandDimdrAsOracleDataReaderPrivateSubForm1_Load(senderAsObject,eAsEventArgs)HandlesMyBase.LoadEndSubPrivateSubButton1_Click(senderAsObject,eAsEventArgs)HandlesButton1.Clicksql="selectdecode('2',1,nvl(a.curr_ks,'未知科室')||'-'||nvl(a.ys_code,'未知医生'),2,nvl(a.curr_ks,'未知科室'),3,nvl(a.zx_ks,'未知科室'),4,nvl(a.curr_ks,'未知科室')||'-'||nvl(a.zzys,'未知医生'))ksdm,bqmc,a.fyglsfxm,"+"sum(a.je*b.jylx)fyhj,sum(round(a.je*nvl(a.self_percent,1),2)*b.jylx)zfje,sum((a.je-a.rlje)*b.jylx)sjfyhj,sum(round((a.je-a.rlje)*nvl(a.self_percent,1),2)*b.jylx)sjzfje"+"fromzy_total_feeb,zy_detail_chargea"+"leftjoingy_bqdmona.curr_bq=gy_bqdm.bqdm"+"wherea.patient_no=b.patient_noanda.jlxhbetweenb.fy_jlxh1andb.fy_jlxh2"+"and(((b.jz_datebetween(to_date('2015/06/0100:00:00','yyyy/MM/ddhh24:mi:ss'))and(to_date('2015/06/3023:59:59','yyyy/MM/ddhh24:mi:ss')))"+"and'1'=1)or((b.rb_datebetween(to_date('2015/06/0100:00:00','yyyy/MM/ddhh24:mi:ss'))and(to_date('2015/06/3023:59:59','yyyy/MM/ddhh24:mi:ss')))"+"and'1'=2andb.rb_dateisnotnull))and(instr('*','^^'||b.brxz||'^^')>0or'*'='*')and(('-1'=-1)or('-1'<>-1andb.fybh='-1'))"+"groupbydecode('2',1,nvl(a.curr_ks,'未知科室')||'-'||nvl(a.ys_code,'未知医生'),2,nvl(a.curr_ks,'未知科室'),3,nvl(a.zx_ks,'未知科室'),4,nvl(a.curr_ks,'未知科室')||'-'||nvl(a.zzys,'未知医生')),a.fygl,bqmc"+"orderbyksdm"conn.ConnectionString="DataSource=ORACLE;UserId=123;Password=123;IntegratedSecurity=no"conn.Open()cmd=NewOracleCommand(sql,conn)dr=cmd.ExecuteReader()DimdtAsNewDataTabledt.Columns.Add("病区")dt.Columns.Add("西药费")dt.Columns.Add("中药费")dt.Columns.Add("中草费")dt.Columns.Add("检查费")dt.Columns.Add("治疗费")dt.Columns.Add("CT费")dt.Columns.Add("放射费")dt.Columns.Add("手术费")dt.Columns.Add("其他费用")dt.Columns.Add("护理费")dt.Columns.Add("材料费")dt.Columns.Add("麻醉费")dt.Columns.Add("彩超费")dt.Columns.Add("化验费")dt.Columns.Add("输血费")dt.Columns.Add("输氧费")dt.Columns.Add("诊查费")dt.Columns.Add("挂号费")dt.Columns.Add("康复费")dt.Columns.Add("床位费")dt.Columns.Add("心电图")dt.Columns.Add("注射费")dt.Columns.Add("合计")dt.Rows.Add("一病区")dt.Rows.Add("三病区")dt.Rows.Add("五病区")Whiledr.Read()Ifdr("ksdm")="10001001"ThenFora=1Todt.Columns.Count-2dt.Rows(0)(a)=dr("fyhj")NextEndIfEndWhiledr.Close()conn.Close()DGV.DataSource=dtEndSubEndClass
while循环部分要如何写?希望能给个代码例子
解决方案
本帖最后由 qq_19585211 于 2015-07-17 16:27:22 编辑
解决方案二:
SQL拼接组织好数据,直接绑定数据源在Datagrid控件上。SQL组织数据,可以要用到行转列,如果列值定死的话,可以更新数据相应的区域里面。