ExecuteReader()异常,原因竟然是数据库执行语句异常~~

1 // 建立数据库连接
2
3 SqlConnection connet = new SqlConnection( " server=(local);user id=sa;password=00;Database=YGXXXT " );
4
5
6 string strsql = " select * from Users where UID=' " + userid.Text + " ' and UPassword= ' " + userpasword .Text + " ' " ;
7
8 // 之前格式一直写成这样 string strsql = "select * from Users where UID=" +userid.Text+" and UPassword= "+userpasword .Text ;
9 // 导致 SqlDataReader reader = sqlcom.ExecuteReader();怎么都读取不了数据,但是困惑的是。reader读取不了数据的时候应该可以跳转到 login_masage.Text = "帐号密码不正确";
10 // login_masage.Style["color"] = "red";为什么一直都是现实ExecuteReader()异常而下不去呢???困惑中ING~~
11 SqlCommand sqlcom = new SqlCommand(strsql, connet);
12 connet.Open();
13
14
15 SqlDataReader reader = sqlcom.ExecuteReader();
16
17 if (reader.Read())
18 {
19 Session[ " userid " ] = reader[ " UID " ];
20 Session[ " userpower " ] = reader[ " userpower " ];
21 if (( int )Session[ " userpower " ] == 1 )
22 {
23 Response.Redirect( " Users.aspx " );
24 }
25 else if (( int )Session[ " userpower " ] == 2 )
26 {
27 Response.Redirect( " personnel_information.aspx " );
28 }
29 else
30 {
31 Response.Redirect( " commonpersonel.aspx " );
32 }
33 }
34 else
35 {
36 login_masage.Text = " 帐号密码不正确 " ;
37 login_masage.Style[ " color " ] = " red " ;
38 }
39
40 connet.Close();

转载于:https://www.cnblogs.com/bobobibi/archive/2011/03/21/bobi.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值