Get BD Rows (MySQL) - WebService Mysql C #

0

I'm having trouble getting the rows .

It does not recognize any variables within cmdMySQL ( @Login ). I tried to put others but nothing if I take the @Login and put the value of email that is in the BD he usually thinks.

My code:

[WebMethod]
public int connectoToMySql()
{
    string Login = "emaildeteste";
    string Pass = "umasenhaforteai";

    string connString = "SERVER=local" + ";" +
        "DATABASE=admin;" +
        "UID=root;" +
        "PASSWORD=*******;" +
        "Allow User Variables = True;";

    MySqlConnection cnMySQL = new MySqlConnection(connString);

    MySqlCommand cmdMySQL = cnMySQL.CreateCommand();

    MySqlDataReader reader;

    cmdMySQL.CommandText = "select * from core_members where 'email' = @Login";

    cnMySQL.Open();

    reader = cmdMySQL.ExecuteReader();

    DataTable dt = new DataTable();
    dt.Load(reader);

    cnMySQL.Close();

    if (dt.Rows.Count > 0)
    {
        return 1;
        Console.WriteLine("Pegou a ROW");
    }
    return 50; //so testando
}
    
asked by anonymous 03.06.2016 / 03:26

1 answer

0

Pass value of parameter @Login for query .

It would look like this:

cmdMySQL.CommandText = "select * from core_members where 'email' = @Login";
cmdMySQL.Parameters.AddWithValue("@Login", Login );

An addendum: the variable Login , according to naming guide the C # should be login .

    
03.06.2016 / 13:38