Search code examples
c#sql-servermissing-datasqldatatypesobjectlistview

Is there a bug in `FastDatalistView` when data is type timestamp from sql server db?


I'm using the ObjectListView wrapper, specifically, a FastDatalistView. Using the Visual Studio visual editor, I configured the FastDatalistView as follows.

    AlternateRowBackColor = ControlLight
    AutoGenerateColumns = True
    Columns = {nothing} (Configured by the wrapper at runtime)
    DataSource = None (Set in code at runtime)
    FullRowSelect = True
    GridLines = True
    MultiSelect = False
    OwnerDraw = True
    ShowGroups = False
    View = Details

Please note that I'm depending on the wrapper’s AutoGenerateColumns feature to autogenerate header column text and aspect names and I'm counting on the wrapper to load data into the list without my code doing anything to it. Why? Because my select statement can and will be constructed with any column name/sql server data type and table name that can be found in any sql server 2014 database

Pertinent parts of my code:

dataTable_X = new DataTable();
dataTable_X.Clear();

dataTable_X = dataAccessLayer.QueryDbGetRecords({arguments needed to construct select statement in QueryDbGetRecords});

if (dataTable_X.Rows.Count <= 0)
{
    MessageBox.Show("The selected table has no records.", "XXXXXXX`", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    return;
}

this.fastDataListViewTableKeys.DataSource = dataTable_X;
this.fastDataListViewTableKeys.RebuildColumns();

fastDataListViewTableKeys.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
fastDataListViewTableKeys.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

dataTable_X.Dispose();
  1. Scenario that works:

I execute select X from Y order by XXXXXXX. X is a sql server 2014 varchar(50) type. An example of the data is 9876-1234. The select statement retrieves 406,000 rows into the datatable. The FastDatalistView displays the data successfully.

  1. Another scenario that works:

I execute select X from Y order by XXXXXXX. X is a sql server 2014 int type. An example of the data is 36. The select statement retrieves 20 rows into the datatable. The FastDatalistView displays the data successfully.

  1. Scenario that fails:

I execute select X from Y order by X. X is a sql server 2014 timestamp type. An example of the data is 0x0000000000F0F5DD. The select statement retrieves 100,000 rows into the datatable. The FastDatalistView displays a column heading. The vertical scroll bar and alternate row backcolor indicate that there are many items in the list, but no data is displayed.

I examined the fastDataListViewTableKeys object using the debugger. The fastDataListViewTableKeys.Columns.Results View[0].AspectName is X as expected. I'm not sure where in fastDataListViewTableKeys I should look to see the list data

Is it that a FastDatalistView can't convert sql server timestamp data into a displayable version as it can with an int, varchar, or, presumably other types that it detects and stringifies??


Solution

  • timestamp is a deprecated synonym for rowversion. It's used for optimistic concurrency and has no displayable form or usage. It's has no relation to time, continuous values, uniqueness or produce any meaningful sort order. From the docs

    Is a data type that exposes automatically generated, unique binary numbers within a database. rowversion is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The rowversion data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime2 data type.

    The only guarantee is that if a row is modified, the rowversion value will be automatically set to something greater than the previous value. The server may decide to generate new values in batches if many rows are modified at the same time.

    Just don't add it to the grid. If you want a high-resolution datetime type use datetime2` with the precision you want.

    rowversion can't be used to detect and retrieve changed records either, by retrieving rows with a rowversion value higher than some stored value. To do that, use Change Tracking which is available in all SQL Server versions and editions