private void comfirmationButton_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(passportNoBox.Text)) { using (var db = new EmbassyEntitiesFramework()) { db.Database.Connection.ConnectionString = connectionString; Visa v = db.Visa.Where(visa => visa.Received_by == passportNoBox.Text).FirstOrDefault <Visa>(); if (v != null) { AddForm a = new AddForm(passportNoBox.Text); a.Show(); } else { MessageBox.Show("Such visa doesn't exist. Try adding it."); } } } }