1
In a unit of measure registration screen, I have to check if the unit that the user is wanting to register, if it already exists, then as I have a DataGrid
populated by a DataTable
, I thought I’d walk the DataTable
and check if this already exists.
So I made the code like this:
//botão salvar
private void simpleButton2_Click(object sender, EventArgs e)
{
//Verifico se os dois textbox estao preenchidos
if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
{
// defino minha string de filtro
string exp = "SIGLA = " + "'" + textBox2.Text + "'";
// Executo a busca com base no meu filtro
DataRow[] find_sigla = dat.Select(exp);
// se o retorno da busca for 0 faz a ação
if (find_sigla.Count() == 0)
{
//Insiro o valor no banco
Classes.Cadastro.Cadastro_estqUn cad_estqun = new Classes.Cadastro.Cadastro_estqUn();
if (cad_estqun.cadastro_unidade(textBox1.Text, textBox2.Text) > 0)
{
textBox1.Text = "";
textBox2.Text = "";
}
}
else
{
MessageBox.Show("Unidade de medida já cadastrada.", "Salvar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
So I heard, that this method I lose performance, proceeds? someone has some better solution?
Thank you.
Your dat is being loader as? And what is your intention!
– Marco Souza