Mokey Mokey - 1 year ago 96
MySQL Question

C# MySQL Values return as Null

Communicating with my 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# communicating with a WPF to MySQL

public string oSearchBan(tBan ban)
tBan bans = new tBan();
string dbConnection = "datasource=;port=3306;username=admin;password=123";
MySqlConnection conDataBase = new MySqlConnection(dbConnection);
MySqlCommand dbSearch;
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");
return bans.GuidOrIP;

Answer Source




bans = searchBan;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download