| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 247 人关注过本帖
标题:[求助]表达式包含无效的字符串常量!!
收藏  订阅  推荐  打印 
huanying205
Rank: 2
等级:注册会员
帖子:107
积分:1232
注册:2007-6-14
[求助]表达式包含无效的字符串常量!!

我想把符合条件的记录显示到DataGirdView控件上,代码是这么写得:
string strRowFilter = "";
string strCmb = this.comboBox1.Text.Trim();
if (this.TextBox1.Text.Trim() != "")
strRowFilter += "序号 like '%" + TextBox1.Text.Trim() + "%'and";
if (this.TextBox2.Trim() != "")
strRowFilter += "姓名 like '" + TextBox2.Text.Trim() + "' and";
if (strCmb != "")
strRowFilter += "籍贯 like '" + strCmb + "' and ";
if (strRowFilter != "")
strRowFilter = strRowFilter.Substring(0, strRowFilter.Length - 5);
tempTable.DefaultView.RowFilter = strRowFilter;
如果在序号的文本框里输入数字后,运行结果就提示说:表达式包含无效的字符串常量:“序号”
输入姓名和籍贯也是一样,请教一下 这是怎么回事呀?

搜索更多相关主题的帖子: 常量  字符  表达  
2007-10-9 10:28
huanying205
Rank: 2
等级:注册会员
帖子:107
积分:1232
注册:2007-6-14

没有指点一下吗?
2007-10-9 10:58
bygg
Rank: 12Rank: 12Rank: 12
来自:乖乖的心中
等级:版主
威望:170
帖子:9765
积分:97351
注册:2006-10-23

string strRowFilter = "select * from tablename where 1=1 ";
string strCmb = this.comboBox1.Text.Trim();
if (this.TextBox1.Text.Trim() != "")
strRowFilter += " and 序号 like '%" + TextBox1.Text.Trim() + "%'";
if (this.TextBox2.Trim() != "")
strRowFilter += " and 姓名 like '" + TextBox2.Text.Trim() + "'";
if (strCmb != "")
strRowFilter += " and 籍贯 like '" + strCmb + "'";

一个天才顶不上十个笨蛋!
书山有路勤为径,学海无涯友相伴。
我的E-mail:mylover624@yahoo.com.cn
2007-10-9 12:37
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.063939 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved