ASP.NET语法错误。。。。求助

yzw1992 2012-05-24 07:03:04
string conStr;
conStr = "Data Source=WIN-58FJ35C0IMC;Initial Catalog=trainbook; Integrated Security=True";
SqlConnection con = new SqlConnection(conStr);
//打开数据库
con.Open();
string sqlsele="select count(*) from 用户 where 用户ID=@name and 密码=@passw";
//创建SqlCommand对象
SqlCommand mycom = new SqlCommand(sqlsele , con);
//使用Parameter的add方法添加参数类型
mycom.Parameters.Add(new SqlParameter("name", SqlDbType.VarChar, 20));
mycom.Parameters.Add(new SqlParameter("passw", SqlDbType.VarChar, 50));
//设置Parameters的参数值
mycom.Parameters["name"].Value = TextBox1.Text;
//使用MD5加密将的用户输入的密码加密
string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text.Trim(), "MD5");
mycom.Parameters["passw"].Value = pwd;

if (Convert.ToInt32(mycom.ExecuteScalar()) > 0)
{
Response .Write ("<script>alert('登录成功!')</script>");
//清空文本框
TextBox1.Text = TextBox2.Text = TextBox3.Text = "";
Response.Redirect ("~/shouye.aspx");
}
红色那句老报错:‘(’附近有语法错误,求高手帮忙看看。不胜感激
...全文
98 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzw1992 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

ExecuteScalar()是返回结果集中的第一行的第一列,不是返回受影响的行数。用的函数不对。
[/Quote]
我用的是count()函数,必然使用这个函数
mahongjing2010 2012-05-25
  • 打赏
  • 举报
回复
ExecuteScalar()是返回结果集中的第一行的第一列,不是返回受影响的行数。用的函数不对。
yzw1992 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

string sqlsele="select count(*)from 用户 where 用户ID=@name and 密码=@passw";
红色部分是中文括号,
改成英文的
string sqlsele="select count(*) from 用户 where 用户ID=@name and 密码=@passw";

mycom.Parameters.Add(new SqlPa……
[/Quote]
不报错了,但是我输入正确的用户名和密码,也没登陆成功。
EnForGrass 2012-05-24
  • 打赏
  • 举报
回复
string sqlsele="select count(*)from 用户 where 用户ID=@name and 密码=@passw";
红色部分是中文括号,
改成英文的
string sqlsele="select count(*) from 用户 where 用户ID=@name and 密码=@passw";

mycom.Parameters.Add(new SqlParameter("@name", SqlDbType.VarChar, 20));
mycom.Parameters.Add(new SqlParameter("@passw", SqlDbType.VarChar, 50));
人生无悔 2012-05-24
  • 打赏
  • 举报
回复

string sqlsele="select count(*) from 用户 where [用户ID]='@name' and 密码='@passw'";

实在不行把执行的sql语句copy到查询分析器中就看出来了

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧