qq_33854610 2016-01-28 07:39 采纳率: 0%
浏览 1437

关于APS.NET WEB开发简单问题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Stu_table;User ID=sa;Password=sa");
        con.Open();
        string sql = string.Format("select count(*) from Student where sName='{0}' and sPwd='{1}'", TextBox1, TextBox2);
        SqlCommand com = new SqlCommand(sql, con);
        int flag =(int) com.ExecuteScalar();
          con.Close();
        if (flag > 0)
        {

            Response.Write("<script> alert('登录成功');</script>");
        }
            Response.Write("<script> alert('账号密码错误');</script>");
    }

}
上面的 名字都没有错数据库名还有表名,那么问题来了 为什么点击登陆候账号密码错误?图片说明图片说明图片说明图片说明

  • 写回答

1条回答 默认 最新

  • Go 旅城通票 2016-01-28 09:59
    关注

    用Text属性,你那样直接对象,调用默认ToString方法可不是输入的值

     string sql = string.Format("select count(*) from Student where sName='{0}' and sPwd='{1}'", TextBox1.Text, TextBox2.Text);
    
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作