I am Trying to teach myself C#. I'm struggling with getting a connection to SQL server. I have a static class, GetSQLConnectionString that returns a connection string.
When I try to call in in my forms class I get the following:
private void button1_Click(object sender, EventArgs e)
{
string conn = GetSQLConnectionString; (Error displayed here
}
Sam HobbsPosted Nov 24, 2023, 7:06 PM
What is the error? It helps to also show the error message.
I do not see () after GetSQLConnectionString. You can see in the other reply that you need to use GetSQLConnectionString(), not GetSQLConnectionString.
Muhammad Imran AnsariPosted Nov 24, 2023, 5:26 PM
To achieve this define a static method in the static class like.
Now call the connection string method in where you need.