DateTime minStartTime =
ListOfProcesesForKilling.Min( p => {
return p.StartTime;
} );
value += $"Min starttime: {minStartTime};";
Code Example Center
Microsoft AX 2012, X++, C#, SQL server, SSRS, Java, JavaFX, Oracle, PL/SQL, Delphi - codes examples, step-by-step tutorials, experiences.
Tuesday, November 4, 2025
c# - How to call Min(), Max() on generic List
c# - How to force JSON enum to save as TEXT instead of a NUMBER
This enum property:
public enum MinimizeActionEnum {
NONE = 0,
CLEAR = 1
}
public MinimizeActionEnum MinimizeAction { get; set; } = MinimizeActionEnum.NONE;
It is saved as INT by default:
"ReportParams": [
{
"Name": "pProdId",
"Description": "",
"MinimizeAction": 0
},
With using that attribute:
[JsonConverter(typeof(JsonStringEnumConverter))]
public MinimizeActionEnum MinimizeAction { get; set; } = MinimizeActionEnum.NONE;
the enum value will be stored as TEXT:
"ReportParams": [
{
"Name": "pProdId",
"Description": "",
"MinimizeAction": NONE
},
Friday, October 31, 2025
Wednesday, October 15, 2025
sql server - How to get detailed info about localdb
List of installed local DBs:
sqllocaldb iOutput:
MSSQLLocalDBMore details about selected:
sqllocaldb info MSSQLLocalDBOutput:
Name: MSSQLLocalDB Version: 15.0.4382.1 Shared name: Owner: domain\pirklj Auto-create: Yes State: Running Last start time: 14.10.2025 14:36:27 Instance pipe name: np:\\.\pipe\LOCALDB#FF67DE7F\tsql\queryList of installed DBLocal versions:
sqllocaldb versionsOutput:
Microsoft SQL Server 2016 (13.0.7037.1) Microsoft SQL Server 2017 (14.0.3391.2) Microsoft SQL Server 2019 (15.0.4382.1) Microsoft SQL Server 2022 (16.0.1000.6)Stopping and deleting of DBLocal instance, creating it with new higher version:
C:\Users\pirklj>sqllocaldb stop MSSQLLocalDB LocalDB instance "MSSQLLocalDB" stopped. C:\Users\pirklj>sqllocaldb delete MSSQLLocalDB LocalDB instance "MSSQLLocalDB" deleted. C:\Users\pirklj>sqllocaldb create MSSQLLocalDB LocalDB instance "MSSQLLocalDB" created with version 16.0.1000.6. C:\Users\pirklj>sqllocaldb start MSSQLLocalDB LocalDB instance "MSSQLLocalDB" started.
Monday, October 13, 2025
c# - How to solve JSON deserialization problem
JSON deserialization returns this error:
Each parameter in the deserialization constructor on type 'cieb_AXReportPrintDLG.ReportParamComboValues' must bind to an object property or field on deserialization. Each parameter name must match with a property or field on the object. Fields are only considered when 'JsonSerializerOptions.IncludeFields' is enabled. The match can be case-insensitive.All fields looks like OK. The problem is in the parameter names in the constructor. This version returns error:
public class ReportParamComboValues {
/* description - for text */
public string Description { get; set; }
/* returned value for SSRS report param */
public string Value { get; set; }
public ReportParamComboValues( string _description, string _value ) {
this.Description = _description;
this.Value = _value;
}
}
This is working:
public class ReportParamComboValues {
/* description - for text */
public string Description { get; set; }
/* returned value for SSRS report param */
public string Value { get; set; }
public ReportParamComboValues( string Description, string Value ) {
this.Description = Description;
this.Value = Value;
}
}
Monday, September 29, 2025
c# - How to solve problem with convension date into string with char "/" in format mask
This result can be obtained when trying to convert a date to a string using a format mask containing the character '/'.
DateTime dt = DateTime.Now; MessageBox.Show( dt.ToString( "yyyy/MM/dd", CultureInfo.GetCultureInfo( "de-DE" ) ) );Output:
2025.09.29The solution is to change the Culture:
DateTime dt = DateTime.Now; MessageBox.Show( dt.ToString( "yyyy/MM/dd", CultureInfo.GetCultureInfo( "en-US" ) ) );Output:
2025/09/29
Wednesday, September 17, 2025
sql server - How to solve problem with CHARINDEX() - value subtraction
If you use this SQL code:
SUBSTRING( a.PackingSlipId, 1, CHARINDEX('-', a.PackingSlipId ) - 1 ) as document,
..you can get this error, even in a situation when CHARINDEX() returns valid values:
Output:
Msg 537, Level 16, State 3, Line 1 Invalid length parameter passed to the LEFT or SUBSTRING function.The solution is to use NULLIF() function:
SUBSTRING( a.PackingSlipId, 1, nullif( CHARINDEX('-', a.PackingSlipId ), 0 ) -1 ) as document,
Friday, September 5, 2025
Tuesday, September 2, 2025
c# - How to add items to combobox with text description from attribute
Define new enum with attributes:
/* types for printing type combobox */
public enum PrintingTypeEnum
{
[Description( "On screen" ) ]
TO_SCREEN,
[Description( "On printer" ) ]
TO_PRINT
}
Fill the combobox with items:
CPrintingType.Items.Clear();
foreach ( PrintingTypeEnum item in Enum.GetValues( typeof( PrintingTypeEnum ) ) )
{
string description = GetEnumDescription( item );
CPrintingType.Items.Add( description );
/* -- default value */
if ( item == PrintingTypeEnum.TO_PRINT )
{
CPrintingType.SelectedIndex = CPrintingType.Items.Count - 1;
}
}
private string GetEnumDescription( Enum _value )
{
FieldInfo field = _value.GetType().GetField( _value.ToString() );
DescriptionAttribute attribute = field?.GetCustomAttribute<DescriptionAttribute>();
return attribute == null ? _value.ToString() : attribute.Description;
}
Output:
Tuesday, May 13, 2025
c# - EF - How to call storedproc with OUTPUT param
You have this stored proc:
ALTER PROCEDURE [dbo].[TEST] -- Add the parameters for the stored procedure here ( @Param1 int, @Message varchar(50) output ) AS BEGIN set @Message = 'xxx'; return '-1'; ENDFor calling it use this code:
var param1 = new SqlParameter( "Param1", System.Data.SqlDbType.Int ); param1.Direction = System.Data.ParameterDirection.Input; param1.Value = iYear; var message = new SqlParameter( "Message", System.Data.SqlDbType.VarChar, 50 ); message.Direction = System.Data.ParameterDirection.InputOutput; message.Value = ""; var ret = context.Database.ExecuteSqlRaw( "EXEC TEST @Param1 = @param1, @Message = @message OUTPUT", param1, message ); MessageBox.Show( message.Value.ToString() ); MessageBox.Show( ret.ToString() );
c# - EF - How to refresh existing DB into EF model
If you have DB and if you want to refresh it`s model into MODEL directory, call this:
dotnet ef dbcontext scaffold "Server=(LocalDB)\MSSQLLocalDB; AttachDbFilename=C:\_projects\vs\FioTax\FioTax\db.mdf; Integrated Security=True;Connect Timeout=30" Microsoft.EntityFrameworkCore.SqlServer --output-dir Models --context AppDbContext --force
Tuesday, February 11, 2025
sql server - How to run export script by sqlcmd
In command.sql is stored SQL select script, this calling performs it and save output to output.txt.
The param "-h -1" removes title row.
The param "-h -1" removes title row.
sqlcmd -S localhost\sqlexpress -d username -U sa -P password -h -1 -m 1 -i "c:\dir\command.sql" -o "c:\dir\output\output.txt"
Monday, January 13, 2025
ax - How to check if the class is running in the batch mode ?
boolean bManualRunning = (BatchHeader::isExecutingInBatch() == false );
Wednesday, December 18, 2024
ax - How to find type used for specified Number Sequence ?
Searching for the data type for the sequence Time_6:
select datatypeid from NUMBERSEQUENCEDATATYPE
where
recid =
(
select NUMBERSEQUENCEDATATYPE from NumberSequenceReference
where
NUMBERSEQUENCEID =
(
select recid from NumberSequencetable
where
NUMBERSEQUENCE = 'Time_6'
)
)
Output:
datatypeid ----------- 8374Then job in AX:
static void Job8(Args _args)
{
info( extendedTypeId2name( 8374 ) );
}
Output:
Thursday, August 8, 2024
SSRS - How to add stripline to chart
The stripline is in this example defined on X axis.
PS: Better variant is to use SSRS function CountDistinct() - solves problem with gaps in axis values:
Remember: the value for StartWith is order of the axis value, not exact value (StartWidth):
=DatePart("ww", today(), FirstDayOfWeek.Monday, FirstWeekOfYear.System )
-min(Fields!skp.Value)).
=CountDistinct( IIF(Fields!skp.Value <= DatePart("ww", today(),
FirstDayOfWeek.Monday, FirstWeekOfYear.System ), Fields!skp.Value, nothing) )
Thursday, July 18, 2024
ax - How to get ItemId by ExternalItemId for specified customer
CustVendExternalItem custVendExternalItem; ItemId itemId; ... itemId = ""; custVendExternalItem = CustVendExternalItem::findExternalItemId( ModuleInventPurchSalesVendCustGroup::Cust, "COMPANYID", sExternalItemId ); if ( custVendExternalItem != null ) itemId = custVendExternalItem.ItemId;
Friday, June 21, 2024
SSRS - How to get first and last day in month
These are useful functions, for example for parameter filling:
First and last day of this month:
First and last day of this month:
=dateadd("m",0,dateserial(year(Today),month(Today),1))
=dateadd("m",1,dateserial(year(Today),month(Today),0))
First and last day of last month:
=dateadd("m",-1,dateserial(year(Today),month(Today),1))
=dateadd("m",0,dateserial(year(Today),month(Today),0))
First and last day of next month:
=dateadd("m",1,dateserial(year(Today),month(Today),1))
=dateadd("m",2,dateserial(year(Today),month(Today),0))
Monday, June 17, 2024
c - How to solve error UNRESOLVED EXTERNAL SYMBOL for static class field
.h
.cpp
class OverloadedOperator {
public:
string name;
float price;
static int n;
};
The problem could be in missing static field initialization in .cpp file. Should be:
.cpp
#include "OverloadedOperator.h"
int OverloadedOperator::n = 0;
Thursday, May 2, 2024
sql server - How to check used count of decimal places in the field
select prodid, remaininventphysical, len(replace( rtrim( replace( convert( varchar, remaininventphysical), '0', ' ' ) ), ' ', '0' ) ) - charindex( '.', replace( rtrim( replace( convert( varchar, remaininventphysical ), '0', ' ' ) ), ' ', '0' ) ) as nonzerodecimalplacesused from PRODBOM order by prodid;Output:
prodid remaininventphysical nonzerodecimalplacesused -------------------- --------------------------------------- ------------------------ 24-015377 0.0600060006000600 14 24-015376 0.0800000000000000 2 24-014563 0.0450045004500450 15 24-013446 0.0450045004500450 15 24-013445 0.0000000000000000 0 24-011934 0.0000000000000000 0 24-008828 0.0000000000000000 0 24-008602 0.0000000000000000 0 24-006598 0.0000000000000000 0 23-039521 0.0000000000000000 0
Thursday, March 21, 2024
c_c++ - How to check DLL architecture (x86 vs x64)
From VS terminal run this command:
dumpbin /headers clib.dllOutput:
Dump of file clib.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
8664 machine (x64)
A number of sections
65FA9AE8 time date stamp Wed Mar 20 09:14:32 2024
0 file pointer to symbol table
0 number of symbols
F0 size of optional header
2022 characteristics
Executable
Application can handle large (>2GB) addresses
DLL
c_c++ - How to check entry points of the DLL
From VS terminal run this command:
dumpbin /exports clib.dllOutput, you can see two entry points:
Dump of file clib.dll
File Type: DLL
Section contains the following exports for CLib.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
2 number of functions
2 number of names
ordinal hint RVA name
1 0 00011249 add = @ILT+580(add)
2 1 000110BE subtract = @ILT+185(subtract)
Summary
1000 .00cfg
1000 .data
1000 .idata
1000 .msvcjmc
3000 .pdata
3000 .rdata
1000 .reloc
1000 .rsrc
8000 .text
10000 .textbss
Tuesday, January 16, 2024
c# - How to use LINQ aggregate() function
This calling performs SUM on Population (with starting value = 0.)
public List<Country> Countries = new(); ... this.Countries.Add( new Country( "Czech", Country.ContinentEnum.EUROPE, 10 ) ); this.Countries.Add( new Country( "Poland", Country.ContinentEnum.EUROPE, 40 ) ); this.Countries.Add( new Country( "China", Country.ContinentEnum.ASIA, 1100 ) ); this.Countries.Add( new Country( "USA", Country.ContinentEnum.AMERICA, 340 ) ); ... int total = this.Countries.Aggregate( 0, (total,b) => total + b.Population ); MessageBox.Show( total.ToString() ); // -> 1490
Thursday, November 30, 2023
c# - How to call custom event
1) Custom event without parameters:
public Action OnBeforeEvaluationEvent; ... if ( OnBeforeEvaluationEvent != null ) OnBeforeEvaluationEvent();2) Custom event with parameter(s):
public delegate void OnAfterEvaluatingDelegate( CodeConditionGroup _conditionGroup ); public event OnAfterEvaluatingDelegate OnAfterEvaluationgEvent; if ( OnAfterEvaluationgEvent != null ) OnAfterEvaluationgEvent( condition );
Friday, November 24, 2023
c#, devexpress - How to make master-detail relation on non-DB objects (List generic )
List<TmpParent> list = new List<TmpParent>(); List<TmpChild> listChildExternal = new List<TmpChild>();Initial data filling:
var p = new TmpParent( "A", "A", true );
p.listInner.Add( new TmpChild() );
list.Add( p );
list.Add( new TmpParent( "B", "B", false, TypeEnum.OPERATOR ) );
list.Add( new TmpParent( "C", "C", true ) );
list.Add( new TmpParent( "D", "D", false ) );
listChildExternal.Add( new TmpChild() { str1="C", str2 = "child1" } );
listChildExternal.Add( new TmpChild() { str1="C", str2 = "child1.1" } );
listChildExternal.Add( new TmpChild() { str1="B", str2 = "child1.2" } );
gridParent.DataSource = list; // master
Find and show detail data:
- First detail list for inner list.
- Second detail list for external list connected with relation.
private void gridViewParent_FocusedRowChanged( object sender,
DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e ) {
if ( e.FocusedRowHandle >= 0 ) {
TmpParent master = gridView1.GetRow( e.FocusedRowHandle ) as TmpParent;
if ( master != null ) {
/* A] try to find in inner list */
gridDetail.DataSource = master.listInner;
/* B] try to find in external list */
gridChildExternal.DataSource =
listChildExternal.Where( x => x.str1 == master.str1 ).ToList();
}
}
}
First grid=master, second grid=detail internal list, third grid=detail external list.
Tuesday, November 14, 2023
c#, devexpress - How to use attributes in GridControl (devexpress)
The attributes in the class can be used as metadata for generated GridControl (devexpress) columns.
Class for rows:
public enum TypeEnum {
[Display(Name = "Type is expression.")]
EXPRESSION = 0,
[Display(Name = "Type is operator.")]
OPERATOR = 1
}
public class TmpParent
{
[Display(
ShortName = "Company",
Name = "Company Name",
Description = "The amount of currently available product",
AutoGenerateFilter = false)
]
public string str1 { get; set; }
[DataType(DataType.Text), StringLength(20, MinimumLength = 3)]
public string str2 { get; set; }
public bool bool1 { get; set; }
public TypeEnum enum1 { get; set; }
[DisplayFormat(DataFormatString = "MMMM/yyyy")]
public DateTime date1 { get; set; }
[DisplayFormat(DataFormatString = "p", ApplyFormatInEditMode = true)]
public float value1 { get; set; }
[DataType(DataType.Currency), Range(200, 5000), Required]
public float value2 { get; set; }
public TmpParent( string _s1, string _s2, bool _b, TypeEnum _enum = TypeEnum.EXPRESSION )
{
str1 = _s1;
str2 = _s2;
bool1 = _b;
enum1 = _enum;
date1 = DateTime.Now;
value1 = 100.1f;
value2 = 300.5f;
}
}
Grid fillings:
var p = new TmpParent( "A", "A", true ); list.Add( p ); list.Add( new TmpParent( "B", "B", false, TypeEnum.OPERATOR ) ); list.Add( new TmpParent( "C", "C", true ) ); list.Add( new TmpParent( "D", "D", false ) ); gridParent.DataSource = list;Output:
Subscribe to:
Comments (Atom)






