I have a little problem with my codes. I'm trying to make my program faster, because it have too big delay, when i'm getting data from mysql and need to make my code faster. Can you help me about this code, is correctly to select * in table and is it good idea? Thank you! It's my code!
public bool GettingPlayers(ref clsConnection c)
{
try
{
MySqlConnection connect = new MySqlConnection(connectionMysql);
connect.Open();
MySqlCommand query = new MySqlCommand("SELECT * FROM Users Where Username='" + Escape(c.Username) + "'", connect);
query.Prepare();
MySqlDataReader dr = query.ExecuteReader();
if (dr.Read())
{
c.Username = dr[1].ToString();
c.Cash = double.Parse(dr[2].ToString());
c.TotalDistance = double.Parse(dr[3].ToString());
c.TotalHealth = double.Parse(dr[4].ToString());
c.Password = dr[5].ToString();
c.Status = int.Parse(dr[6].ToString());
c.IpAdress = dr[7].ToString();
c.TotalJobsDone = int.Parse(dr[8].ToString());
}
else
{
dr.Close();
connect.Close();
return false;
}
dr.Close();
connect.Close();
return true;
}
catch (Exception ex)
{
Form1 frm1 = new Form1();
frm1.LogTextToFile("sqlError", "GettingPlayers - " + ex);
return false;
}
}
Also I have a public string Escape(string str) => str.Replace("'", "\'").Replace(""", "\"");