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>");
}
}
上面的 名字都没有错数据库名还有表名,那么问题来了 为什么点击登陆候账号密码错误?