Gussy Rodriguez
Gussy Rodriguez

Reputation: 63

How can i fix this error? c# asp linq

A few minutes ago this part of my code was functional with success, few minutes after i see this when i compile the project

Error image result

And the code is:

    string Cat = ddlCategoria.SelectedValue;
    int? MaxIdCat = (from p in db.tblProducto
                     where p.IdCategoria == Cat
                     select p.IdProducto).Max() + 1;

    txtIdEmp.Text = Convert.ToString(MaxIdCat ?? +1);

Upvotes: 4

Views: 73

Answers (1)

karthik krishnasamy
karthik krishnasamy

Reputation: 46

Please make sure Cat is having value in variable and as well as in table. If that value is not existing in table you have to handle is null on the entire linq query.

Upvotes: 3

Related Questions