private void button1_Click(object sender, EventArgs e) { if (textBox1.ReadOnly == false && String.IsNullOrEmpty(textBox1.Text) == false && String.IsNullOrEmpty(textBox2.Text)) { bool jaexiste = false; bool controle = false; if (dataGridView1.Rows.Count > 0) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (controle == false) { if (textBox1.Text == dataGridView1.Rows[i].Cells[1].Value.ToString() || textBox2.Text == dataGridView1.Rows[i].Cells[2].Value.ToString()) { MessageBox.Show("Já existe este cadastro!"); jaexiste = true; controle = true; } } } } if (jaexiste == false) { string message = "Você deseja cadastrar esta Empresa: \n" + textBox1.Text + " ?"; string caption = "Empresa"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result; // Displays the MessageBox. result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { string Stored = "CriarCadEmpresa"; DALCadastro.AUXCadCriarEmpresa(Stored, textBox1.Text, textBox2.Text); dataGridView1.DataSource = DALCadastro.AUXCadListar("ListarCadEmpresa"); textBox1.Text = ""; textBox2.Text = ""; textBox1.ReadOnly = true; textBox2.ReadOnly = true; label3.Text = ""; } } } }