I am getting the following error:
Object reference not set to an instance of an object
I don't know what is the cause of this error and how to solve it, here is my code:
while(dr.Read())
{
string variant = dr.GetString(0);
int size = dr.GetInt32(1);
int quantity = dr.GetInt32(2);
DataRow x = dt.Rows
.Cast<DataRow>()
.Where(r => r["variant_name"].Equals(variant) && r["size"].Equals(size))
.FirstOrDefault();
x["quantity"] = quantity;
}
I'm getting the error on this line -> x["quantity"] = quantity;
I'm wondering why it would give a null value because I checked in my database that it should return exactly one match.