Last post Sep 28, 2015 05:24 AM by Li Wang
Sep 26, 2015 09:55 AM|urpalshu|LINK
Below is the method I get object reference not set to an instance error.
When I add cd.TryAdd(3434,"MyCode")
at line cd.TryAdd(ID, Price.code);
Why would I get object refence error, I have initialized my dictionary with the new key work.
Please help, with suggestions.
private ConcurrentDictionary<int, string> MyMethodName((List<HCustomer> HCustomer, string RecordAction)
int ID = 0;
ConcurrentDictionary<int, string> cd = new ConcurrentDictionary<int, string>();
foreach (var Price in HCustomer)
if (NewRecord == 1)
ID = (InsertPrice(Price));
ID = (UpdatePrice(Price));
if (ID > 0)
cd = null;
public int UPdatePrice(HCustomer HCustomer)
int Id = 0;
using (SqlCommand command = CreateCommand("MyStoredProcedure", CommandType.StoredProcedure, this.CompanyConnection))
Sep 28, 2015 05:24 AM|Li Wang|LINK
if (ID > 0) cd.TryAdd(ID, Price.code); else cd = null;
cd will be setted to null when ID not larger than 0. You could debug your code line by line.