I want to get the server details from a textdocument, so i passed the parameter (loacalhost) to connectionstring. but the following error occurs.
"A field initializer cannot reference the non-static field"
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
labelget();
}
string localhost ;
string myconnectionstring = "Server=" + localhost + "; Database=amepos2015; Uid=root; Pwd=fatehshah"; /*error on this line */
public void labelget()
{
using (StreamReader sr = new StreamReader("C:/Requirement.txt"))
{
while ((localhost = sr.ReadLine()) != null)
{
localhost = sr.ReadLine();
}
}
}
catch (Exception ea)
{
if (MessageBox.Show("File not found", "Error", MessageBoxButtons.OK) == DialogResult.OK)
{
Application.Exit();
}
}
Console.Read();
}
}