网站首页  |   业界社区  |  电信社区  |  技术社区   |  极客社区  |  游戏社区  |  生活社区   |   科技博客  |   同事录
TechWeb-技术社区


标题: [asp.net] 菜鸟在登陆页面遇到的拦路虎Please help me!
流氓鱼
TW高级会员
Rank: 4



UID 117265
精华 13
积分 842
帖子 457
阅读权限 50
注册 2007-3-16
状态 离线
发表于 2008-8-28 09:54 资料 短消息 加为好友
菜鸟在登陆页面遇到的拦路虎Please help me!

问题:string sql = "select * from tb_user where userName='" + userName + "' and userPwd='" + Pwd + "'"; 0g9z,q/}6[!e4U0L"u/F/C&f8D
请问各位老大上面这句话有什么用啊?还有这些引号是根据什么规律引起来的啊?为什么这么引啊?

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:57
这样就看得清楚了:

C# code

string sql = string.Format("select * from tb_user where userName='{0}' and userPwd='{1}'", userName, Pwd);

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:57
根据用户名和密码判断tb_user表中是否有这个用户.
字符串的拼接.单引号里面是双引号,双引号里面是单引号.
在SQL语句,查询的字符串要加单引号.

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:57
C# code

string sql = "select * from tb_user where userName='" + userName + "' and userPwd='" + Pwd + "'";


就是字符串拼接,把5个字符串拼接在一起,效果上和下面的语句是一样的:

C# code

string sql = string.Format("select * from tb_user where userName='{0}' and userPwd='{1}'", userName, Pwd);

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:57
C# code/*
假设
string userName = "ABC";
string Pwd      = "123";


string sql = "select * from tb_user where userName='" + userName + "' and userPwd='" + Pwd + "'";

就是把
select * from tb_user where userName='
ABC
' and userPwd='
123
'
依次拼接在一起,

最后得到:
select * from tb_user where userName='ABC' and userPwd='123'

*/

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:57
C# code/*
假设
string userName = "ABC";
string Pwd      = "123";


string sql = "select * from tb_user where userName='" + userName + "' and userPwd='" + Pwd + "'";

就是把
"select * from tb_user where userName='"
"ABC"
"' and userPwd='"
"123"
"'"
依次拼接在一起,

最后得到:
"select * from tb_user where userName='ABC' and userPwd='123'"


当然,下面的语句看起来更清晰些,效果是一样的:
string sql = string.Format("select * from tb_user where userName='{0}' and userPwd='{1}'", userName, Pwd);


*/

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:58
哦!那他为什么不直接加一单引号就好了像userName=‘userName’!为什么还要再加一双引号啊!呵呵!本人比较笨,老大行行好给我解解疑惑!

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:58
双引号表示里面是字符串的内容啊,其内容是不包括双引号本身的,我在6楼已经解释得够清楚了。

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:58
C# code比如
"Hel" + "lo, w" + "orl" + "d."
得到
"Hello, world."
这个字符串,你能理解吧?

那么:
"Hel" + "lo, '" + "world" + "'."
就是得到:
"Hello, 'world'."
对吧?

引用 回复 顶部
游客
未注册









发表于 2008-9-4 11:58
那也就是说'" + "world" + "'这个是一个整体!对吧!

引用 回复 顶部
查看积分策略说明快速回复主题
选项 标题 Smilies
禁用 URL 识别
禁用 Smilies
禁用 Discuz!代码
使用匿名发帖
使用个人签名
接收新回复邮件通知
内容





当前时区 GMT+8, 现在时间是 2008-11-23 08:39
京ICP证060517号

本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.5.0 © 2001-2008 Comsenz Inc.
Processed in 0.020627 second(s), 7 queries

清除 Cookies - 联系我们 - TechWeb.com.cn - Archiver - WAP