sql语句拼接
来源:互联网 发布:淘宝哪个买正品乔丹 编辑:程序博客网 时间:2024/05/16 14:10
在组合查询是怎样用一个简单的方法,判断局部控件是否为空呢?
if (cmbrelation1.Text == "") //第一个逻辑符号为空 { Control[] arrcontrol = new Control[3]; arrcontrol[0] = cmbfields1;//第一行文本框的名字 arrcontrol[1] = cmboperator1; arrcontrol[2] = txtcontext1; //调用函数判断控件内容是否为空 bool falg; falg = issomeempty(arrcontrol); if (falg == true) { MessageBox.Show("请将第一行信息填写完整"); enGroupQuery = null; return; } enGroupQuery.debug = 1; }
用这个方法就可以了。
public bool issomeempty(Control[] arrcontrol) { bool flag; int i = 0; foreach (Control item in arrcontrol) { if (item.Text == string.Empty) { i += 1; } else { } } if (i > 0) { flag = true; } else { flag = false; } return flag; }
组合查询时,我们把所有的信息用一个实体类装好,传递给d层
//将参数传递给实体,调用重新的方法 enGroupQuery.fileds1 = ToName(cmbfields1.Text); enGroupQuery.fileds2 = ToName(cmbfields2.Text); enGroupQuery.fileds3 = ToName(cmbfields3.Text); enGroupQuery.operator1 = cmboperator1.Text; enGroupQuery.operator2 = cmboperator2.Text; enGroupQuery.operator3 = cmboperator3.Text; enGroupQuery.context1 = txtcontext1.Text.Trim(); enGroupQuery.context2 = txtcontext2.Text.Trim(); enGroupQuery.context3 = txtcontext3.Text.Trim(); enGroupQuery.relation1 = ToName(cmbrelation1.Text); enGroupQuery.relation2 = ToName(cmbrelation2.Text); // enGroupQuery.table = Getdtable(); enGroupQuery.table = Getdtable(); if (enGroupQuery == null) { return; } else { //调用外观层 Facade.GroupWorkFacade groupworkuser = new Facade.GroupWorkFacade(); DataTable table = groupworkuser.Groupworkway(enGroupQuery);
然后返回的table就组合查询得到的信息了,不论是否所有的信息都填写完整,都赋值传递到D层。其中加了一个属性debug。
在局部判空中,如果不为空,就赋值debug。
尝试很多次用存储过程。但是没有成功,SQL语句只能在D层写了。以前在vb机房中,只是按着葫芦画瓢,不懂+“”+ 这个是什么意思,空不是什么都没有吗?原来不加空,有会使两个独立的单词合到一起。
还有就是 string str = "select * from A where B=' " + value + " ' "; ‘ “ + value + ” ’ 这样写是什么意思?这里value代表一个变量,如果直接在字符串中写变量,就会化成字符串了,我是刚刚才懂。
调试,可视化文本,非常好用,大赞。我为什么刚刚知道它的好处?
看一下D层。
public DataTable groupworkway(Entity.GroupQuery engroupquery) { string sql; SQLHeper.sqlhelper sqlhelper = new SQLHeper.sqlhelper();//创建一个sqlHeper类对象 SqlParameter[] sqlParams = { new SqlParameter("@fileds1",engroupquery.fileds1 ), new SqlParameter("@fileds2",engroupquery.fileds2 ), new SqlParameter("@fileds3",engroupquery.fileds3 ), new SqlParameter("@operator1",engroupquery.operator1 ), new SqlParameter("@operator2",engroupquery.operator2 ), new SqlParameter("@operator3",engroupquery.operator3 ), new SqlParameter("@context1",engroupquery.context1 ), new SqlParameter("@context2",engroupquery.context2), new SqlParameter("@context3",engroupquery.context3), new SqlParameter("@relation1",engroupquery.relation1 ), new SqlParameter("@relation2",engroupquery.relation2 ), new SqlParameter("@table",engroupquery.table ) }; string strl = engroupquery.table; if (engroupquery.debug==1) { sql = @"SELECT * FROM " + engroupquery.table + " WHERE " + engroupquery.fileds1 + engroupquery.operator1 + "@context1"; //string str = "select * from A where B=' " + value + " ' "; //sql = @"SELECT * FROM " + strl + " WHERE @fileds1 + '" + engroupquery.operator1 + "'+ @context1"; DataTable table = SQLHeper.sqlhelper.GetDataTable(sql, CommandType.Text, sqlParams); return table; } if (engroupquery.debug==2) { sql = @"SELECT * FROM " + strl + " WHERE " + engroupquery.fileds1 + engroupquery.operator1 + "@context1 " + engroupquery.relation1 + " " + engroupquery.fileds2 + engroupquery.operator2 + "@context2"; // sql = sql + engroupquery.relation1 + engroupquery.fileds2 + engroupquery.operator2 + "@context2"; DataTable table = SQLHeper.sqlhelper.GetDataTable(sql, CommandType.Text, sqlParams); return table; } if (engroupquery.debug==3) { sql = @"SELECT * FROM " + strl + " WHERE " + engroupquery.fileds1 + engroupquery.operator1 + "@context1 " + engroupquery.relation1 + " " + engroupquery.fileds2 + engroupquery.operator2 + "@context2"; sql += " " + engroupquery.relation2 + " " + engroupquery.fileds3 + engroupquery.operator3 + "@context3"; DataTable table = SQLHeper.sqlhelper.GetDataTable(sql, CommandType.Text, sqlParams); return table; }
else { return null; } }
0 0
- 技巧-----sql语句拼接
- 拼接sql语句
- SQL语句拼接。。。
- sql语句拼接
- SQL查询语句拼接
- sql 语句的拼接
- iwebshop sql语句拼接
- sql语句拼接
- SQL查询语句拼接
- 拼接SQL语句[Oracle]
- excel 拼接sql 语句
- BBP项目Sql语句拼接
- java拼接sql语句例子
- sql语句参数拼接Bug
- 多条件下SQL语句拼接
- activerecord中拼接SQL语句
- 拼接SQL语句缺少“break”
- Mybatis之SQL语句拼接
- 文件下载
- 总结了几个最常用的MyEclipse的快捷键,没掌握的赶快记下了
- POJ2115 C Looooops(扩展欧几里得算法)
- Web前端
- oracle根据身份证更新出生日期(15位与18位身份证都可)
- sql语句拼接
- 几个优化方法
- VS2015 C#6.0 中的那些新特性
- 网络回调
- HashMap 和 Hashtable
- Eclipse控制台输出信息的控制
- [Android6.0][RK3399] 去掉滑动锁屏(swipe lock)
- Android 文件打开方式用setDataAndType方式
- node.js之框架