private void Add_Click(object sender, EventArgs e) { string connectionString = "Data Source=DESKTOP-IPDREAN\\SQLEXPRESS2019;Initial Catalog =Flightservice;" + "Integrated Security=True"; SqlConnection sqlconnection = new SqlConnection(); SqlCommand selectCommand; SqlDataReader R; try { if (firstname3.Text == "" || lastname3.Text == "") { MessageBox.Show("enter a name ."); } // name existance verificaton int name_verification = 0; sqlconnection.ConnectionString = connectionString; sqlconnection.Open(); string selectStatement = "select [firstname],[lastname] From [dbo].[passenger] "; selectCommand = new SqlCommand(selectStatement, sqlconnection); R = selectCommand.ExecuteReader(); while (R.Read()) { if (firstname3.Text == R[0].ToString() && lastname3.Text == R[1].ToString()) { //it's a flag to indicate if name exists or not name_verification = 1; } } if (name_verification == 1) { MessageBox.Show("ALREADY REGISTERED!!"); } else { MessageBox.Show("ADD A NAME."); Form name = new Passengers(); name.Show(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "connection failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } }