I am trying to check my database to see if a user's member_hwid column is null or not. If it's null, then run the function to update the hwid. However, if the column is not null; then run the code to login. The problem is, when the code is ran; I'm always getting the response "Not Null"; even when the user's hwid field is set as null. As seen below, here is my code:
public void CHECKANDWRITEHWID()
{
string server = "72.167.59.139";
string database = "DATABASENAME";
string uid = "YOURUID";
string password = "YOURPASSWORD";
string ssl = "None";
string connectionString = $"SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};SSL Mode={ssl};";
using var connection = new MySqlConnection(connectionString);
connection.Open();
//using var command = new MySqlCommand("SELECT name = @name FROM core_members WHERE members_pass_hash IS NULL OR members_pass_hash = '';", connection);
using var command = new MySqlCommand("SELECT member_hwid FROM core_members WHERE name = @name AND member_hwid IS NULL OR member_hwid = '';", connection);
//using var command = new MySqlCommand("", connection);
command.Parameters.AddWithValue("@name", maskedTextBox1.Text);
//var hwid = (string)command.ExecuteScalar();
var hwid = command.ExecuteNonQuery();
if (hwid == null)
{
MessageBox.Show("null");
}
else
{
MessageBox.Show("Not null");
}
}
I have tried setting the user's member_hwid to null, to numbers and letters, or just an empty string. No matter the case; it is always returning the response as Not null. If the column "member_hwid" for let's say John Doe is empty, then I need it to return saying null and if it's not; to return saying it's not. I have tried adjusting my commands for the query as seen above but I am now lost; what am I doing wrong?