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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题