How would I sort a DataTable using Linq? I've tried the following but received the error:
InvalidCastException was unahndled by user code. Specified cast is not allowed.
var query = from c in allFiles.AsEnumerable() orderby c.Field<DateTime>(1)
descending select c;
That would suggest that for at least some row, field 1 isn't a DateTime. If it may be null, you might want to try DateTime? instead. Or check that it really is that field in the first place... maybe use a name instead of a number?
The table was dynamically generated and had no actual specified column dataType. When I created the column and specified the dataType the issue was resolved.
I'm not sure why I didn't realize the dataType wasn't defined until after I posted this question.
Related
I am working on a project where I have to fetch only distinct data from the table display in the dropdown. How can I do that? I am using '''hasura-graphql''' data-provider for it. So how can I get only distinct data from a particular column?
Thanks in advance.
I think passing a default "distinct_on" filter with the column name as value will do the job. Also, hasura recommends sorting by this column in first position.
It is typically recommended to use order_by along with distinct_on to
ensure we get predictable results (otherwise any arbitrary row with a
distinct value of the column may be returned). Note that the
distinct_on column needs to be the first column in the order_by
expression.
So i set default sort:
<ReferenceInput
reference="yourTable"
source="yourDistinctColumn"
sort={{field: "yourDistinctColumn", order: "ASC"}}//or DESC, your choice
filter={{distinct_on: "yourDistinctColumn"}}
>
<SelectInput optionText="yourDistinctColumn"/>
</ReferenceInput>
https://hasura.io/docs/1.0/graphql/manual/queries/distinct-queries.html
I have written open formula in Pentaho Report Designer 5.0.1 as:
=SINGLEVALUEQUERY("SELECT name FROM income_product where order_no=1";)
Rather than writing a query on data set and call from SINGLEVALUEQUERY() I want the string value from the above query.
PRD doesn't complain about the above formula as syntax error; it just returns null/nothing. What (if anything) is wrong in that formula?
I want to write that formula to generate dynamic column name for a report having order number 1 or greater. Is there any other way to make the column name dynamic for a report?
By "Dynamic column name", I mean making different organization have unique income_product_order.
If I just assign the order_no of income_product it automatically gets income_product_name as the column name for all organizations.
Did you set up your connection correctly? try adding a query over that connection and paste that query there. Does it return any data?
This is a good blog post on the subject: https://www.on-reporting.com/blog/using-queries-in-formulas-in-pentaho/
You can enable the "Display the index columns (...)" option under Settings. It'll allow you to reference columns either by name or by index (column0, column1, etc.)
I have this here:
Dim query = FromTableRows.Select(Function(Row) Row.Item(_SqlSyntaxChecker.SelectedFields(0)))
Row is a normal DataRow, so I can get the field value of the rows like this: Row.Item(0), Row.Item(1), etc.
SelectedFields contains the field names of the FromTableRows.
Now, I would like to select all the fields in the SelectedFields list, while the number of the selected fields can vary.
Is this possible? How should I modify the code?
Thanks.
You can simply make use of the ItemArray property, if I understand your question correctly.
FromTableRows.Select(Function(Row) Row.ItemArray)
The ItemArray property is an object array that contains the elements found in the DataRow. You will, of course, lose any mapping via this method from columns to elements, but it sounds like that's what you want.
I'm working on a module to pull data from Oracle into a PowerShell data table, so I can automate some analysis and perform various actions based on the results. Everything seems to be working, and I'm casting columns into specific types based on the column type in Oracle. The problem I'm having has to do with null dates. I can't seem to find a good way to capture that a date column in Oracle has a null value.
Is there any way to cast a [datetime] as null or empty?
Here's an easy function to test if a value from a database column is NULL:
function test-sqlnull{
Param($value)
return [System.DBNull]::Value.Equals($value)
}
If you need to store a null in a datetime field, just set it to [DBNull]::Value.
I think I have a solution that will work. Rather than attempting to set the field as null or empty, I'm not setting it at all. Now the empty value can be identified by checking if the file type is [System.DBNull].
$data | ? {$_.myDate.GetType() -eq [System.DBNull]}
I have looked around and have not found anything similar to what I am asking.
Short of extending the CActiveRecord class is there a way to query just the primary key values (or any column's values) of a table and have an array of those values returned instead of a collection of activerecord objects?
ie
ModelName::model()->getColumnValues('column_name');
I keep having to get a list of record that match a certain condition and then run through the results to pull out the column values I need. I would like to cut out the last step and just get the values instead of the entire record.
Any ideas?
Using a CDbCommand you can execute a query and fetch the results from one column with the queryColumn method. queryColumn returns the results from the first column.
Example:
$command = Yii::app()->db->createCommand("SELECT column FROM table WHERE ...");
$result = $command->queryColumn();