05-23-2012, 06:31 PM
like this for example
public void Write()
{
try
{
TextWriter tr = new StreamWriter("Settings.cfg");
tr.WriteLine("## MYSQL");
tr.WriteLine("SQL_HOST=" + textBox_host.Text);
tr.WriteLine("SQL_DBASE_CHAR=" + textBox_Chrdatabase.Text);
tr.WriteLine("SQL_DBASE_DATA=" + textBox_Datadatabase.Text);
tr.WriteLine("SQL_USER=" + textBox_User.Text);
tr.WriteLine("SQL_PASSWORD=" + textBox_password.Text);
tr.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
public void Read()
{
try
{
TextReader tr = new StreamReader("Settings.cfg");
string line;
while ((line = tr.ReadLine()) != null)
{
if (line.Contains("#") || line.Length == 0)
{
}
else
{
string[] values = line.Split(=);
foreach (string v in values)
{
if (values[0] == "SQL_HOST") host = values[1];
if (values[0] == "SQL_DBASE_CHAR") database = values[1];
if (values[0] == "SQL_DBASE_DATA") database1 = values[1];
if (values[0] == "SQL_USER") user = values[1];
if (values[0] == "SQL_PASSWORD") password = values[1];
}
}
}
textBox_Chrdatabase.Text = database;
textBox_Datadatabase.Text = database1;
textBox_host.Text = host;
textBox_password.Text = password;
textBox_User.Text = user;
tr.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}

