一、今天收获是学会了写多表查询语句,以及如何将数据库文字转化为汉子

多表查询语句的写法:

select a.字段名,b.字段名,c.字段名,d.字段名 ,case  when a. 字段名=0  then '汉字'  when a.字段名=1 then '汉字'   end as 字段别名  from 表名1 as a inner join 表名2 as b  On a.字段名=b.字段名 inner join 表名3 as c  On a.字段名=c.字段名  inner join 表名4 as d  On a.字段名=d.字段名.

 

二、Sql语句拼接

    StringBuilder sb = new StringBuilder();
            sb.Append("Select zy.zymc ,gv.postName,dv.UnitName ,sxzy,u.bkUserID,UserName,u.sfzh,u.bmxlh,u.zkzh,case when u.ifjf=0 then '未交费' when  u.ifjf=1 then '已交费成功' end as iss , case when u.ifsh=0 then '未审核' when u.ifsh=1 then '审核通过' when u.ifsh=2 then '审核不通过' when u.ifsh=3 then '审核通过缴费成功'   end as ifsh  from  bm_examcj as zy inner join bm_ExamUser  as u On zy.zkzh=u.zkzh  inner join  bm_post as gv On gv.postID=u.postID inner join bm_ExamUnit as dv On dv.UnitID=u.bkUnitID  where 1=1 ");
            if (txtxm.Text != string.Empty)
                sb.Append(" and UserName like '%" + txtxm.Text.Trim() + "%' ");
            if (txtbmxlh.Text != string.Empty)
                sb.Append(" and bmxlh like '%" + txtbmxlh.Text.Trim() + "%' ");
            if (txtzy.Text != string.Empty)
                sb.Append(" and zy like '%" + txtzy.Text.Trim() + "%' ");
            dp.CommandText = sb.ToString();
            DataTable dt = dp.ExecuteDataTable();
            if (dt.Rows.Count != 0)
            {
                this.DataGridView1.BindData(dt);
            }

posted on 2012-06-01 11:20  微笑点燃希望  阅读(2650)  评论(0编辑  收藏  举报
font=white