Parameterized Query for MySQL with C#

前端 未结 6 1679
情歌与酒
情歌与酒 2020-11-22 02:06

I have the code below (I\'ve included what I believe are all relevant sections):

private String readCommand = \"SELECT LEVEL FROM USERS WHERE VAL_1 = ? AND V         


        
6条回答
  •  悲&欢浪女
    2020-11-22 02:23

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=result;password=1234");
        con.Open();
    
        MySqlCommand cmd = new MySqlCommand("Select * from users where username=?username and password=?password", con);
        cmd.Parameters.Add(new MySqlParameter("username", this.Login1.UserName));
        cmd.Parameters.Add(new MySqlParameter("password", this.Login1.Password)); 
    
        MySqlDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows ==true)
        {
            e.Authenticated = true;
        }
    }
    

提交回复
热议问题