//Filtra os clientes por nome private void buttonFiltrar_Click(object sender, EventArgs e) { if (textBoxfiltar.Text.Length > 0) { bindingNavigator1.AddNewItem.Enabled = false; myDb.Dispose(); myDb = new StandAutomoveisContainer(); (from cliente in myDb.Clientes where cliente.Nome.ToUpper().StartsWith(textBoxfiltar.Text.ToUpper()) orderby cliente.Nome select cliente).ToList(); dataGridView1.DataSource = myDb.Clientes.Local.ToBindingList(); } else { bindingNavigator1.AddNewItem.Enabled = true; myDb.Dispose(); myDb = new StandAutomoveisContainer(); (from cliente in myDb.Clientes orderby cliente.Nome select cliente).Load(); dataGridView1.DataSource = myDb.Clientes.Local.ToBindingList(); } }
//Dá dispose da base de dados private void FormInicial_FormClosing(object sender, FormClosingEventArgs e) { myDb.Dispose(); }