it's not quite right to start your mdi form from login form. your login form should be called from mdi form. it can be done in several places for example:
In MDI form constructor(user wouldn't see MDIForm before login)
public MDIForm()
{
using (AuthorizeForm form = new AuthorizeForm())
{
if (form.ShowDialog() != DialogResult.OK)
{
System.Environment.Exit(1);
return;
}
}
}
public class AutorizeForm()
{
private void login_Click(object sender, EventArgs e)
{
try
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = BillingApplication.Properties.Settings.Default.DB_BillingConnectionString;
conn.Open();
string selectString = "SELECT * FROM login WHERE (Username = '" + textBox1.Text + "' AND Password = '" + textBox2.Text + "')";
OleDbCommand cmd = new OleDbCommand(selectString, conn);
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
DialogResult = DialogResult.OK;
return;
}
}
catch (Exception)
{
MessageBox.Show("Error with Database Connection");
}
finally
{
if(conn != null && conn.State != == ConnectionState.Closed)
{
conn.Close();
}
}
DialogResult = DialogResult.NO;
}
}