private void textSQL_KeyDown(object sender, KeyEventArgs e) { String sQuery; if (e.KeyCode == Keys.F5) { if (String.IsNullOrEmpty(textSQL.Text)) { MessageBox.Show("pesquisa incorreta"); } else if (String.IsNullOrEmpty(textSQL.SelectedText)) { sQuery = textSQL.Text; DAL.Connection conexao = new DAL.Connection(); conexao.Conectar(); BindingSource bind = new BindingSource(); bind.DataSource = conexao.DataTable(sQuery); gridSQL.AutoGenerateColumns = true; gridSQL.DataSource = bind.DataSource; } else { sQuery = textSQL.SelectedText; DAL.Connection conexao = new DAL.Connection(); conexao.Conectar(); BindingSource bind = new BindingSource(); bind.DataSource = conexao.DataTable(sQuery); gridSQL.AutoGenerateColumns = true; gridSQL.DataSource = bind.DataSource; } } }