Archive for the ‘.Net’ Category

Prepare your report date fields for Excel export

May 26, 2008

I made some rdlc reports to be shown in report viewer.
Often theese reports are exported to Excel, for further processing.

I made a typed dataset for my tables, defining the date columns as ‘xs:date’
To remove the timestamp in the report, I used FormatDateTime(Fields!OrderDate.Value, 2), and everything was fine….. Untill the users start complaining, that the date columns where not formatted as date in the exported excel sheet.

The solution is to use the ‘Format’ property of the field, here you can specify the formatting for dates.
For example =”dd/MM/yyyy”. Here you can also make an expression to handle different language options etc.
This approach preserves the date format in exorted excel sheets.

Improving code readability when using iDB2 .Net connector for iSeries

May 8, 2008

I have done a few apps over the last years using IBM’s .Net data connector for iSeries (i5)

When you use the DataReader, you usually end up with a lot of places where you access the content of your datareader like this: ‘dr.GetString(8)’
The problem is that after some time you can’t remember which fields actually had number 8 in the array, and you have to go to your SQL statement to find out.

I came across the method “GetOrdinal” on the DataReader object and wondered what was the purpose for that, and after a little googling, I found out, that it actually solved one of my everyday problems (a small one, but anayway;))

So here is how it works.
In the scope of ‘while(dr.Read())’, you call the method with the DB2 field name, and it returns an integer telling the index of the field in the datareader array: 

int db2CustomerNo = dr.GetOrdinal(“ODKUND”);

and then in your code, you can access the field using your assigned integer like this:

dr.GetString(db2CustomerNo)

No rocket science – just a little trick, that makes your day a little bit easier;)