Mokey Mokey - 1 month ago 7
C# Question

asp.net Returning Wrong Value with parameter

So I Got a search return to work... however it's not finding the exact entry in the database...

MySqlConnection con = new MySqlConnection(dbConnection);
MySqlCommand cmd;
con.Open();
MySqlDataReader dbReader;
string cmdText = "SELECT `BanID`, `GUID`, `BanTime`, `Reason`, `BanType`, `Proof` FROM `a3bans`.`bans` WHERE `GUID` LIKE @pGUID";


cmd = new MySqlCommand(cmdText, con);

cmd.Parameters.AddWithValue("@pGUID", "%" + bans.GuidOrIP + "%");


When I search for "e7af78997ef220a557c97a1a4c11e0c2" which is a persons ID, it returns with "fa32f7c456b368e17a278f3b165a550d" which is a completely different persons ID.

If I change my query to
WHERE
GUID
= @prmGUID"
it returns as
null
value.

What am I doing wrong that it wont return the string I am looking for?

Answer
MySqlConnection con = new MySqlConnection(dbConnection);
 MySqlCommand cmd;
 con.Open();
 MySqlDataReader dbReader;
 string cmdText = "SELECT `BanID`, `GUID`, `BanTime`, `Reason`, `BanType`, `Proof` FROM `a3bans`.`bans` WHERE  `GUID` LIKE '%@pGUID%'";

cmd = new MySqlCommand(cmdText, con);
SqlParameter param  = new SqlParameter();
param.ParameterName = "@pGUID";
param.Value         = bans.GuidOrIP;
cmd.Parameters.Add(param);

by using this code it will look for same bans.pGUID in table and then return result. try it.