Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Reference Exception while adding new Row to DataTable
    primarykey
    data
    text
    <p>I'm having this strange issue while adding a new row to a <code>DataTable</code>. It does not occur every time, but while running the application, I get null reference exception while there are no objects found null. </p> <p>Here is the code:</p> <p><em>Firstly Clear the Row and Columns of the DataTable:</em></p> <pre><code>dtLibraries.Rows.Clear(); dtLibraries.Columns.Clear(); dtLibraries.Columns.Add("Col1"); dtLibraries.Columns.Add("Col2"); dtLibraries.Columns.Add("Col3"); dtLibraries.Columns.Add("Col4"); dtLibraries.Columns.Add("Col5"); dtLibraries.Columns.Add("Col6"); dtLibraries.Columns.Add("Col7"); dtLibraries.Columns.Add("Col8"); dtLibraries.Columns.Add("Col9"); </code></pre> <p><em>Then reading another DataTable and Writing Data to this table:</em> </p> <pre><code>for (int s = 0; s &lt;= dttemp.Rows.Count - 1; s++) { dttemp1.Clear(); dttemp1 = business.GetOutputLibraries("SimObjectOutputRequestSet", dttemp.Rows[s].ItemArray[2].ToString(), dttemp.Rows[s].ItemArray[1].ToString(), dttemp.Rows[s].ItemArray[0].ToString()); for (int j = 0; j &lt;= dttemp1.Rows.Count - 1; j++) { DataRow dr = dtLibraries.NewRow(); dr["Col1"] = dttemp1.Rows[j].ItemArray[0].ToString(); dr["Col2"] = dttemp1.Rows[j].ItemArray[1].ToString(); dr["Col3"] = dttemp1.Rows[j].ItemArray[2].ToString(); dr["Col4"] = dttemp.Rows[s].ItemArray[0].ToString(); dr["Col5"] = dttemp.Rows[s].ItemArray[2].ToString(); dr["Col6"] = dttemp.Rows[s].ItemArray[1].ToString(); dr["Col7"] = cmbObject.Text.ToString(); dr["Col8"] = cmbLibraryType.Text; dr["Col9"] = cmbLibrarySubType.Text; dtLibraries.Rows.Add(dr); /// Exception occurs on this line } } </code></pre> <p>StackTrace:</p> <pre class="lang-none prettyprint-override"><code>at System.Data.NameNode.Eval(DataRow row, DataRowVersion version) at System.Data.BinaryNode.EvalBinaryOp(Int32 op, ExpressionNode left, ExpressionNode right, DataRow row, DataRowVersion version, Int32[] recordNos) at System.Data.BinaryNode.Eval(DataRow row, DataRowVersion version) at System.Data.DataExpression.Invoke(DataRow row, DataRowVersion version) at System.Data.Index.AcceptRecord(Int32 record, IFilter filter) at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32 changeRecord) at System.Data.Index.RecordStateChanged(Int32 record, DataViewRowState oldState, DataViewRowState newState) at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2) at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception&amp; deferredException) at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent) at System.Data.DataRowCollection.Add(DataRow row) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload