Last post Aug 27, 2018 07:34 AM by PatriceSc
Aug 26, 2018 08:30 PM|feiyim|LINK
Am just puzzled about why this line of code is throwing an "Object reference was not set to an instance of an object".
var printJobDataTable = printJob.Label.DatabaseLabelVariables.Tables;
DatabaseLabelVariables returns a Dataset and has the following code,
public DataSet DatabaseLabelVariables
string query = "SELECT * FROM ILSLabelVars WHERE label=@label;";
SqlParameter label = new SqlParameter("@label", this.uniqueName);
return ILSDBConnector.SelectDataSet(query, label);
So am wondering which object haven't i initialized.
I tried to cast the DataTable returned from DatabaseLabelVariables explicitly but still throwing the same error.
var printJobDataTable = (DataTable)printJob.Label.DatabaseLabelVariables.Tables;
I also tried to explicitly instantiate printJobDataTable so that i just assign to it, but still am getting the same error.
var printJobDataTable = new DataTable();
printJobDataTable = printJob.Label.DatabaseLabelVariables.Tables;
Aug 27, 2018 07:26 AM|Ackerly Xu|LINK
It seems that the code you have posted is not complete.
You haven't posted the ILSDBConnector.SelectDataSet method.
What's your variable printJob and what's printJob.Label?
Please post more of your code, so that we could find what causes the error.
Aug 27, 2018 07:34 AM|PatriceSc|LINK
See first what is null using the debugger. It could be also Label or DatabaseLabelVariables.
Edit: if not familiar with the debugger you could start with code such as :
if (printJob.Label==null) throw new NullReferenceException("Label");
if (printJob.Label.DatabaseLevelVariables==null) thow new NullReferenceException("DatabaseLevelVariables");