using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

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)
    {
        int i = this.checkLogin(TextBox1 .Text ,TextBox2 .Text );
        if (i > 0)
        {
            Response.Write("<script>alert('用户名和密码都正确，成功登录！')</script>");
        }
        else
        {
            Response.Write("<script>alert('用户名称或密码错误，请重新输入！')</script>");
        }
    }
    public int checkLogin(string loginName, string loginPwd)
    {
        SqlConnection con = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=SQL_Data");
        SqlCommand myCommand = new SqlCommand("select count(*) from myuser where sname =@loginName and  spwd =@loginPwd", con);
        myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.VarChar, 50));
        myCommand.Parameters["@loginName"].Value = loginName;
        myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.VarChar, 50));
        myCommand.Parameters["@loginPwd"].Value = loginPwd;
        myCommand.Connection.Open();
        int i = (int)myCommand.ExecuteScalar();
        myCommand.Connection.Close();
        return i;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
    }
}
