I have a listBox1 in my MainForm that I want to fill with the results from a MySQL query (results are put into 'tmpPeers'). The listBox1 keeps giving me the error above. here's the code:
internal async Task<Account> FromSchool(string school)
{
var tmpCommand = Core.Instance.Database.Connection.CreateCommand();
tmpCommand.CommandText =
$@"SELECT `name`, `grade`, `hobbies`, FROM `accounts` WHERE `school` = '{school}';";
var tmpPeers = await tmpCommand.ExecuteReaderAsync();
if (!tmpPeers.HasRows)
return null;
tmpPeers.Close();
MainForm.listBox1.Items.Add(tmpPeers);
return null;
}
please help! I have pretty limited coding knowledge.
I want the results from the query to fill the listBox, but right now I run it and it is empty.
EDIT: THIS IS NOT THE SAME AS THE MARKED DUPLICATE. The method in my problem is already static, yet the error still comes up. Resharper prompts me to make the field listBox1 static, but when I do i get the error "Member 'MainForm.listBox1' cannot be accessed with an instance reference; qualify it with a type name instead.