I am trying to create a SQL database in c# by having my program connect to the server. I am having a problem with creating a login screen. The problem is in order to create a login screen. I am trying to pass 2 strings to the connection class and am unable to do so since the statement is static?
public class sqlconnect
{
public String us;
public String pas;
public SqlConnection myConnection = new SqlConnection("user id=" + (us) + ";" +
"password=" + (pas) + ";server=PANDORA;" +
"Trusted_Connection=yes;" +
"database=NHS; " +
"connection timeout=30");
}
ERROR - A field initializer cannot reference the non-static field, method, or property
If I try and make "us" or "pas" static I am unable to pass information from my main class to this one. I would be grateful if someone could point out what I'm doing wrong as I am not an expert at C# I must admit. Thank you.