using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Data.SqlTypes;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    //数据库操作
    protected void btnCommit_Click(object sender, EventArgs e)
    {
                 string name = this.txtName.Text.Trim();
        string pass= this.txtPwd.Text.Trim(); //根据自己配置的数据库来进行修改 Data Source=JEWEL\\SQLEXPRESS;JEWEL\\SQLEXPRESS是我的数据源
//test是我的数据库,ID=sa;Password=123456,我的SQL2005的账号和密码,根据自己数据库的信息更改。
        string STR = "Data Source=JEWEL\\SQLEXPRESS;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=123456";
        SqlConnection conn = new SqlConnection(STR);
        SqlCommand cmd = conn.CreateCommand();
        //查询
        //cmd.CommandText="select * from Login where username='"+name+"' and password='"+pass+"'";
        //    conn.Open();
        //    SqlDataReader dr=cmd.ExecuteReader();
        //    if (dr.Read() == true)
        //    {
        //        Response.Write("用户存在");
        //    }
        //    else
        //    {        //        Response.Write("用户不存在");
        //    }        //增加
        //cmd.CommandText = "insert into Login values('" + name + "','" + pass + "')";        //conn.Open();
        //int a = cmd.ExecuteNonQuery();
        //if (a > 0)
        //{
        //    Response.Write("成功!");
        //    //Response.Write("<script>alert('添加成功');</scirpt>");
        //}
        //else
        //{
        //    //Response.Write("<script>alert('失败');</scirpt>");
        //}
        //conn.Close();
        //删除
        //cmd.CommandText = "delete from Login where username='" + name + "' ";
        //conn.Open();
        //try{
        //int a = cmd.ExecuteNonQuery();
        //if(a>0)
        //{
        //    Response.Write("删除成功!");
        //}
        //else
        //{
        //    Response.Write("删除失败!");
        //}
        //}catch(Exception)
        //{
        //}        //修改
        cmd.CommandText = "update Login set password='"+pass+"' where username='"+name+"'";        conn.Open();
        int a = cmd.ExecuteNonQuery();
        if (a > 0)
        {
            Response.Write("修改成功!");
            
        }
        else
        {
            Response.Write("修改失败!");
        }
        conn.Close();
   }
 
}