Lambda expression with AND operator in lambda expression

.net c# entity-framework lambda linq

Question

I get an error (

Object reference not set to an instance of an object

) when i try to do the database operation, i can't seem to find what's wrong, must be something from this p.ADRESA.Equals(listBox1.SelectedItem.ToString() because without it the code works but i need two conditions, please help

 Int16 idValoare =Convert.ToInt16 (comboBoxIDValoare.SelectedItem.ToString());

        if (selectedTabel.Equals("CUSTOMER"))
        {
            if (selectedColoana.Equals("ADRESA"))
            {
                CUSTOMER customer = db.CUSTOMERs.First(p => (p.CUSTOMERID == idValoare) && (p.ADRESA.Equals(listBox1.SelectedItem.ToString())));
                customer.ADRESA = textBoxValoare.Text;
                db.SaveChanges();
            }
}
1
2
5/24/2015 3:08:48 PM

Popular Answer

You can't use ToString() in LINQ method, but you can try this:

string selectedItem = listBox1.SelectedItem.ToString();
CUSTOMER customer = db.CUSTOMERs.First(p => (p.CUSTOMERID == idValoare) && (p.ADRESA.Equals(selectedItem)));

I hope that helps you. Please feedback.

6
3/7/2013 9:41:47 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow