简体   繁体   中英

Asp.Net C# Mysql Select Query with Parameters

I need to get data from database . I added some parameters in my SQL. When I try to execute this sql , I got zero record. Which is my code;

        MysqlCon c = new MysqlCon();
        MySqlConnection con = c.GetMySqlConnection();
        MySqlCommand command = con.CreateCommand();
        con.Open();
        command.CommandText = "SELECT COUNT(*) FROM KASA WHERE KUL_AD=@AD ";
        command.Parameters.AddWithValue("@AD", "egemenhalici@gmail.com");
        int rc = Convert.ToInt32(command.ExecuteScalar());

If I write this sql without any parameters, I am getting datas.

What am I doing wrong?

thank you

Thank you very much for your attention. But I think I found my problem.

I don't know but I wrote ? for @ it worked.

    MysqlCon c = new MysqlCon();
    MySqlConnection con = c.GetMySqlConnection();
    MySqlCommand command = con.CreateCommand();
    con.Open();
    command.CommandText = "SELECT COUNT(*) FROM KASA WHERE KUL_AD=?AD ";
    command.Parameters.AddWithValue("?AD", "egemenhalici@gmail.com");
    int rc = Convert.ToInt32(command.ExecuteScalar());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM