各位高手,请帮我检查一下我的 C#登录验证代码 那里错了!!急 啊

[复制链接]
查看11 | 回复3 | 2009-12-1 02:20:45 | 显示全部楼层 |阅读模式
sql语句有错误,不过我的看法和楼上的有些不同 SqlCommand cmd = new SqlCommand("select * from user where name=" +
"'" + this.textBox1.Text + "'and password=" +
"'" + this.textBox2.Text + "'", myc); 这句中的and左面少了一个空格。
回复

使用道具 举报

千问 | 2009-12-1 02:20:45 | 显示全部楼层
帐号密码核对在哪'
回复

使用道具 举报

千问 | 2009-12-1 02:20:45 | 显示全部楼层
1.user是SQL保留关键字,作为数据库表需要加上中括号[user],部分位置需要空格(注意不要在全角状态输入)2.你的登陆验证方式存在注入,建议修改string sql= "select * from [user] where name=@name and password=@pwd";SqlCommand cmd = new SqlCommand(sql, conn);cmd.Parameters.Add("@name", SqlDbType.NChar).Value = name;cmd.Parameters.Add("@pwd", SqlDbType.NChar).Value = pwd;
回复

使用道具 举报

千问 | 2009-12-1 02:20:45 | 显示全部楼层
字符串类型的单引号?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行