Mokey Mokey - 1 month ago 6
MySQL Question

C# asp.net MySQL Values return as Null

Communicating with my asp.net keeps returning a null value... I'm actually not sure why.

I've used Post Man to push information back to it to see the result excluding the use of the WPF to ensure it's my API. The only result I can return is the result I am searching for... I.E. BanID returns BanID All others return a null value.

I've Used this method for other stuff on the same API and it works fine... Somewhere I made a typo.

This is for a search box on a C# asp.net communicating with a WPF to MySQL

[HttpPost]
[Route("A3Bans/searchBan")]
public string oSearchBan(tBan ban)
{
{
tBan bans = new tBan();
string dbConnection = "datasource=127.0.0.1;port=3306;username=admin;password=123";
MySqlConnection conDataBase = new MySqlConnection(dbConnection);
MySqlCommand dbSearch;
conDataBase.Open();
MySqlDataReader dbReader;
string selectQuery = "Select * FROM a3bans.bans WHERE BanID=" + int.Parse(ban.BanID);

dbSearch = new MySqlCommand(selectQuery, conDataBase);
dbReader = dbSearch.ExecuteReader();

if (dbReader.Read())
{
tBan searchBan = new tBan();
searchBan.GuidOrIP = dbReader.GetString("GUID");
//searchBan.BanType = dbReader.GetString("BanType");
searchBan.BanReason = dbReader.GetString("Reason");
searchBan.Proof = dbReader.GetString("Proof");
bans.Equals(searchBan);
}
dbReader.Close();
return bans.GuidOrIP;
}

Answer

Change

bans.Equals(searchBan);

To

bans = searchBan;