如何默认插入用户(客户端)条目?

How to Insert User(Client Side) Entry By Default?

我有

管理端和客户端

我只有一个 table 用于管理员登录和客户端登录,请参阅参考图片

当用户登录然后以用户身份插入条目时?

参考:

https://imgur.com/a/PDoVSi9

我想前:

数据库条目

用户类型:用户
EmailId: benssok@gmail.com
密码:bens1234
名字:尼克斯
姓氏:安德鲁

代码:

c# 注册客户端:

protected void Button1_Click(object sender, EventArgs e)
{
    string firstname = txtFirstName.Text;
    string lastname = txtLastName.Text;
    string emailid = txtEmailId.Text;
    string password = txtclientpassword.Text;
    ClientLogin_Click(firstname, lastname, emailid, password);
}`enter code here`

void ClientLogin_Click(string firstname,string lastname,string emailid,string Password)
{
    string conn = ConfigurationManager.ConnectionStrings["connstr"].ToString();
    SqlConnection cn = new SqlConnection(conn);

    string Insertquery = "Insert into tbladminclient(FirstName,LastName,EmailId,Password) values(@FirstName,@LastName,@EmailId,@Password)";
    SqlCommand cmd = new SqlCommand(Insertquery, cn);
    cmd.CommandType = CommandType.Text;

    cmd.Parameters.AddWithValue("@FirstName", firstname);
    cmd.Parameters.AddWithValue("@LastName", lastname);
    cmd.Parameters.AddWithValue("@EmailId", emailid);
    cmd.Parameters.AddWithValue("@Password", Password);

    try
    {
        cn.Open();
        int validateOperation = cmd.ExecuteNonQuery();
        if (validateOperation > 0)
        {
            Response.Write("successfully Registration");
            Response.Redirect("ClientLogin.aspx");
        }
        else
        {
            Response.Write("Not successfully Registration");
        }
    }
    catch (SqlException e)
    {
        Response.Write("error");
    }
    finally
    {
        cn.Close();
    }
}

AdminLogin页面//相同登录(AdminSide)和相同登录(ClientSide)时出现的问题有什么区别?如何解决这个问题?如何识别用户(客户端)和管理员(管理员)登录?

protected void Button1_Click(object sender, EventArgs e)
        {
            string userName = txtEmailId.Text;
            string Password = txtUserPassword.Text;
            Login_Click(userName, Password);
        }

        void Login_Click(string emailid, string Password)
        {
            string conn = ConfigurationManager.ConnectionStrings["connstr"].ToString();
            SqlConnection cn = new SqlConnection(conn);

            SqlCommand cmd = new SqlCommand("select * from tbladminclient where EmailId=@EmailId and Password=@Password", cn);
            cn.Open();
            cmd.Parameters.AddWithValue("@EmailId", emailid);
            cmd.Parameters.AddWithValue("@Password", Password);

            SqlDataReader dr = cmd.ExecuteReader(); //data read from the database 

            if (dr.HasRows == true)   //HasRows means one or more row read from the database
            {
                Response.Write("successfully Login");
            }
            else
            {
                Response.Write("Not successfully Login");
            }
            cn.Close();
        }

问题是相同的Login(AdminSide)sameLogin(ClientSide)有什么区别?如何解决这个问题?如何识别用户(客户端)和管理员(管理员)登录?

首先当用户(客户端)填写注册表时去数据库执行查询

ALTER TABLE [tbladminclient]
ADD CONSTRAINT df_UserType
DEFAULT 'User' FOR UserType; //whenever you insert then Bydefault Entry is User: 

如何识别用户是客户端还是管理员

代码: 用户登录

protected void Button1_Click(object sender, EventArgs e)
{
    string emailid = txtemailId.Text;
    string password = txtPassword.Text;

    Client_Login(emailid,password);
}

void Client_Login(string emailid,string password)
{
    string conn = ConfigurationManager.ConnectionStrings["connstr"].ToString();
    SqlConnection cn = new SqlConnection(conn);

    SqlCommand cmd = new SqlCommand("select * from tbladminclient where EmailId=@EmailId and Password=@Password", cn);
    cn.Open();
    cmd.Parameters.AddWithValue("@EmailId", emailid);
    cmd.Parameters.AddWithValue("@Password", password);
    SqlDataReader dr = cmd.ExecuteReader(); //data read from the database 

    if (dr.HasRows == true)//HasRows means one or more row read from the database
    {
        if (dr.Read())
        {
            if (dr["UserType"].ToString() == "User")
            {
                Response.Write("successfully Client Login");
            }
            else
            {
                Response.Write("Not successfully Client Login");
            }
        }
    }
    else
    {
        Response.Write("Not Found");
    }

    cn.Close();
}

管理员登录

protected void Button1_Click(object sender, EventArgs e)
{
    string userName = txtEmailId.Text;
    string Password = txtUserPassword.Text;
    Login_Click(userName, Password);
}

void Login_Click(string emailid, string Password/*string UserType*/)
{
    string conn = ConfigurationManager.ConnectionStrings["connstr"].ToString();
    SqlConnection cn = new SqlConnection(conn);

    SqlCommand cmd = new SqlCommand("select * from tbladminclient where EmailId=@EmailId and Password=@Password", cn);

    cn.Open();

    cmd.Parameters.AddWithValue("@EmailId", emailid);
    cmd.Parameters.AddWithValue("@Password", Password);

    SqlDataReader dr = cmd.ExecuteReader(); //data read from the database 

    if (dr.HasRows == true)//HasRows means one or more row read from the database
    {
        if (dr.Read())
        {
            if (dr["UserType"].ToString() == "admin")
            {
                Response.Write("Successfully Admin Login");
            }
            else
            {
                Response.Write("Not successfully Admin Login");
            }
        }
    }
    else
    {
        Response.Write("Not Found");
    }
    cn.Close();
}