Get BD (Mysql) Rows - Webservice Mysql C#

Asked

Viewed 70 times

0

I’m having a hard time getting Rows.

It recognizes no variable within the cmdMySQL (@Login). I tried to put other but nothing if I take the @Login and put the value of email who is in the comic book he thinks normally.

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
}

1 answer

1


Missed passing the value of the parameter @Login to the query.

Would that way:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.