I am getting this error and I don't know why.
'An object reference is required for the non-static field, method, or property'
Why do I need to have an object reference here? My code is as below:
public string GetChanges()
{
string changelog = "";
MySqlConnection connection = new MySqlConnection("server=127.0.0.1;uid=root;pwd=pass;database=data");
try
{
connection.Open();
MySqlCommand cmd = new MySqlCommand("SELECT `change_log` FROM version WHERE ID = '1'", connection);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if (!reader.IsDBNull(0))
{
changelog = reader.GetString(0);
}
}
connection.Close();
}
catch
{
//MessageBox.Show(e.Message, "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
return changelog;
}
I am calling the above function like so:
string changelog = GetChanges();
Why is an object reference required in this case? I cannot use static because I am creating a Web Service which doesn't work with static methods. How can I alter this to use objects?
Thanks