.NET学习爱好者

热爱编程事业

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sConnectionString = "Password=123;User ID=sa;"+ "Initial Catalog=tianlu1.0;"+ "Data Source=(local)";
       string sql = "select * from admin where username='" + TextBox1.Text.Trim() + "' and password='" + TextBox2.Text.Trim() + "'";
        try
        {
            SqlConnection cn = new SqlConnection(sConnectionString);
            SqlCommand cmd = new SqlCommand("userlogin", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@username", TextBox1.Text.Trim());
            cmd.Parameters.Add("@password", TextBox2.Text.Trim());
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "tblAuthors");
            DataTable tblAuthors = ds.Tables[0];
            if (tblAuthors.Rows.Count >= 1)
            {
                Response.Write("aaaaaaaaaa");

            }
            else
{
                Response.Write("登陆失改了!");
            }
        }
        catch
        {
            Response.Write("出现错误了!");
        }
       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {

        //string mySelectQuery = "insert into admin(username,password) values('"+TextBox1.Text.Trim()+"','"+TextBox2.Text.Trim()+"')";
        string myConnectString = "Password=123;User ID=sa;" + "Initial Catalog=sq_zb;" + "Data Source=(local)";
        try
        {
            SqlConnection cn = new SqlConnection(myConnectString);
            SqlCommand cmd = new SqlCommand("insertuser",cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@username", "11111111");
            cmd.Parameters.Add("@password", "2222222222");
            cn.Open();
            int a = cmd.ExecuteNonQuery();
            Response.Write(a);
            cn.Close();
        }
        catch
        {
            Response.Write("sssssss");
        }

    }
}

posted on 2007-01-11 19:49  风景  阅读(322)  评论(0编辑  收藏  举报