Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just posting this for completeness sake, this is the adjusted code that Mert Erol came up with in the accepted answer. I believe that there was a miscommunication about whether ID numbers are required or not. They are not.</p> <p>The DataTable DataRows contain a ItemArray where the first column is the DateTime and the second column is the DataValue.</p> <p>Here's Merl's code wrapped into a function that I am now using. Thanks again Mert, I'd give you a few more upvotes if I could!</p> <p><strong>EDIT: UPDATED</strong> for correct handling of cases where data is missing for multiple days. Using <code>TimeSpan</code> seemed most appropriate to get an accurate count of hours between data points.</p> <pre><code>public DataTable fillMissingHours(DataTable currentDataTable) { // iterates through the current DataTable to find missing data and fill it in with // the correct DateTime and NULL DataValue DataRow row; DateTime curRowDt, nextRowDt; object curObj, nextObj; // Used only for conversions for (int i = 0; i &lt; currentDataTable.Rows.Count - 1; ++i) { curObj = currentDataTable.Rows[i][0]; nextObj = currentDataTable.Rows[i + 1][0]; curRowDt = Convert.ToDateTime(curObj); nextRowDt = Convert.ToDateTime(nextObj); if (curRowDt.AddHours(1.0) != nextRowDt) { TimeSpan deltaTime = nextRowDt - curRowDt; for (int j = 1; j &lt; deltaTime.TotalHours; ++j) { ++i; row = currentDataTable.NewRow(); row.ItemArray = new object[] { curRowDt.AddHours(j), null }; currentDataTable.Rows.InsertAt(row, i); } } } return currentDataTable; } </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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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