社区
C#
帖子详情
怎样去空格?!!!!
ChristianBoris
2003-02-24 10:43:55
有三个DropDownList,他们第一个选项都是空字符型,当用SQL语句查询数据库时如果都为空时默认查找的表中的三个空字段,则找不到数据,用SQL语句拼凑太麻烦(如果能拼凑起来也行),有没有一个函数像DELPHI中的TRIM一样可以去空格!!
真诚向各位高手请教!!
...全文
219
16
打赏
收藏
怎样去空格?!!!!
有三个DropDownList,他们第一个选项都是空字符型,当用SQL语句查询数据库时如果都为空时默认查找的表中的三个空字段,则找不到数据,用SQL语句拼凑太麻烦(如果能拼凑起来也行),有没有一个函数像DELPHI中的TRIM一样可以去空格!! 真诚向各位高手请教!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wang852963
2003-02-24
打赏
举报
回复
to lin_x_gang(林风) :
你那样如果所有条件为空时,SQL语句变成"select *from table1 where"就会出错。所以最好把SQL语句变成"select *from table1 where 1=1",然后再进行判断,如你写的一样。
ChristianBoris
2003-02-24
打赏
举报
回复
不是吧有7个字段呢!
lbx1979
2003-02-24
打赏
举报
回复
先判断再生成字符串不行吗
lin_x_gang
2003-02-24
打赏
举报
回复
更正:
......以此类推.之后加上
sStrTerm = "where " + sStrTerm;
sStr = sStr + sStrTerm;
^-^.
lin_x_gang
2003-02-24
打赏
举报
回复
string sStr = " select *from table1";
string sStrTerm = "";
if(this.DropDownList1.SelectItem.Text.Trim() != "")
{
sStrTerm = sStrTerm + "cpbid = '" +
this.DropDownList1.SelectItem.Text+"'";
}
if(this.DropDownList2.SelectItem.Text.Trim() != "")
{
if(sStrTerm == "")
{
sStrTerm = sStrTerm + "cpbid = '" +
this.DropDownList2.SelectItem.Text+"'";
}
else
{
sStrTerm = sStrTerm + " and cpbid = '" +
this.DropDownList2.SelectItem.Text+"'";
}
}
......以此类推.
比较笨一点,谁有好办法.
ChristianBoris
2003-02-24
打赏
举报
回复
如果为空的字段太多就判断不了了!因为有WHERE和AND在里面,所以光判断不行,要7!种情况。
QQ86087516
2003-02-24
打赏
举报
回复
判断一下不就搞定了
string sql="select * from table1 where 1=1";
if(**!="")
sql=sql+ " and 条件=×××";
...
...
...
ChristianBoris
2003-02-24
打赏
举报
回复
我的意思是有空格是系统默认也是一个字段,我想让它为空时不执行!例如:
sStr=" select *from table1"+
" where cpbid = '" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbtype ='"+this.DropDownList1.SelectItem.Text+"'"+
" and cpbsubrela ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbpopedom ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbinvectry ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbtradetyp ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbregorgn = '" + this.DropDownList1.SelectItem.Text+"'";
当几个条件为空是就跳过不执行比如CPBID=‘’则
sStr=" select *from table1"+
" where cpbtype ='"+this.DropDownList1.SelectItem.Text+"'"+
" and cpbsubrela ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbpopedom ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbinvectry ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbtradetyp ='" + this.DropDownList1.SelectItem.Text+"'"+
" and cpbregorgn = '" + this.DropDownList1.SelectItem.Text+"'";
请教!!
starky
2003-02-24
打赏
举报
回复
表述不清;)
maotin
2003-02-24
打赏
举报
回复
String.Trim(),
klxyz
2003-02-24
打赏
举报
回复
字符串的方法Str.Trim()与Delphi中类似
但不太明白你想干什么 呵呵 你说的太模糊了
fushuming
2003-02-24
打赏
举报
回复
当然有了,也是用Trim()的
ChristinaR
2003-02-24
打赏
举报
回复
真的很简单!:)
ChristianBoris
2003-02-24
打赏
举报
回复
这个问题太简单我已经搞定了!只要设定一个必须输入的框就搞定了!要不WHERE 和 AND不好控制!
chinchy
2003-02-24
打赏
举报
回复
只能一个一个判断,再构造SQL语句,没别的办法.
======================
不要告诉我说用DELPHI不用判断,这是不可能的
hsj178
2003-02-24
打赏
举报
回复
string sStr = " select *from table1 where";
string sStrTerm = "";
if(this.DropDownList1.SelectItem.Text.Trim() != "")
{
sStrTerm = sStrTerm + "cpbid = '" +
this.DropDownList1.SelectItem.Text+"'";
}
//下面的是一样递推的判断
if(this.DropDownList2.SelectItem.Text.Trim() != "")
{
if(sStrTerm == "")
{
sStrTerm = sStrTerm + "cpbid = '" +
this.DropDownList2.SelectItem.Text+"'";
}
else
{
sStrTerm = sStrTerm + " and cpbid = '" +
this.DropDownList2.SelectItem.Text+"'";
}
}
。。。。。
sStr = sStr + sStrTerm;
清除某个目录下所有程序的文件名中的
空格
在做帮助文件时,你是否为文件名中有
空格
而不能正确编译帮助呢?不用担心了,今天我为了解决这个问题写了一个批量更改文件名的小程序,他可以一下帮你去除所有文件名中的
空格
!这可是个好工具阿!从中你还会学到如何...
2010网络疑难问题总结
想通过思科认证吗???来看这些疑难解答吧!!!有关网络的方方面面,都可以在上面找到答案!!!2009网络工程师教材集合!!!多个关键字请用
空格
分隔,最多填写5个。点击右侧Tag快速添加
至少8位密码,包括大写、小写、数字、特殊字符中的三种即可(一般强密码规则)
正则表达式:^(?![A-Za-z]+$)(?![A-Z\\d]+$)(?![A-Z\\W_]+$)(?![a-z\\d]+$)(?...[A-Za-z]+$)匹配后面不全是(大写字母或小写字母或大小写组合)的情况,排除了(1)全是大写字母(2)全是小写字母(3)大小写组合的...
js正则表达式之 (?=) (?!)
百度空间改得不知怎么用了,把以前的文章转过来 今天搞了一个东西,拿到一个url后,想在url的search后面加个参数,当然这个url是任意的 var url = ‘http://www.aa.com/b.html?a=b#c=d’, adtag...
js密码正则,6-18位字符,数字、字母、特殊字符-=_+,. ,必须两种及以上组合
6-18位字符,数字、字母、特殊字符-=_+,. ,必须两种及以上组合 /^(?![\d]+$)(?![a-zA-Z]+$)(?![-=+_.,]+$)[\da-zA-Z-=+_.,]{6,18}$/ 如果不限制特殊字符种类 /^(?...[^\da-zA-Z]+$).{6,18}$/
C#
110,539
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章