login.aspx.cs

来自「A Portal for uploading images, videos an」· CS 代码 · 共 48 行

CS
48
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 login : System.Web.UI.Page
{
    SqlConnection sqlcon = new SqlConnection();
    SqlCommand sqlcmd = new SqlCommand();
    String connectionString = "Data Source=jpsoft02\new;Initial Catalog=starsparkz;Integrated Security=True";
    Int32 uid = 0;


    
    protected void Page_Load(object sender, EventArgs e)
    {
        
      
    }   
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection sqlcon = new SqlConnection(connectionString);
        sqlcon.Open();
        SqlCommand sqlcmd = new SqlCommand("SELECT userid FROM mylogintable where username='" + txtusname.Text + "' and userpass='" + txtpassword.Text + "'", sqlcon);
        SqlDataReader sqldr = sqlcmd.ExecuteReader();
        while (sqldr.Read())
        {
            uid =Convert.ToInt32(sqldr["userid"]);
            if (uid > 0)
            {
                Response.Redirect("myaccount.aspx?id=" + sqldr["userid"]);
            }
            else
            {
                Response.Redirect("Invalidlogin.aspx");
            }
        }
        sqlcon.Close();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?