Wednesday, March 25, 2009

Money Validation

Money field validation using controlvalidator

<_asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Invalid Amount"
Operator="DataTypeCheck"
Type="Double">

Tuesday, March 10, 2009

Row number for grouped data

Rownumber function returns the number of the row of the dataset

EMP_NAME
Emp1
Emp2
Emp3
Emp3
Emp3
Emp4

If we would like to groupby EMP_NAME and show the row number beside each row, the result will be :

Row number EMP_NAME
1 emp_1
2 emp_2
3 emp_3
6 emp_4

As you can see the row number value is not correct, actually it is correct because the rownumber function returns the number of row inside the dataset not inside the grouped data in the report

Now we need to display the row number for what we see in the report instead of what is inside the dataset

I am going to use runningvlaue function for the grouped data inside "table1"

=runningvalue(Fields!EMP_NAME.Value,countdistinct,"table1")

Result:

Rownumber EMP_NAME
1 emp_1
2 emp_2
3 emp_3
4 emp_4

Runningvalue function: accumulates the result of any aggregate function except for rownumber and runningvalue.

Monday, March 9, 2009

Next line command

How to display data in the next line inside the same data field


=Fields!EMP_Name.Value & System.Environment.NewLine() & Fields!EMP_Address.Value

Result:

EMPNAME
ADDRESS

Friday, March 6, 2009

Report page footer

Add page number to Reprot Page Footer

="Page " & Globals!PageNumber

Result: Page1, Page2,…..etc

To display the total number of pages you can use “Globals!TotalPages”

="Page " & Globals!PageNumber & "of " & Globals!TotalPages

Result: “Page1 of 2”, “Page2 of 2”

Thursday, March 5, 2009

Row number

Select the first n rows
the following example show how to retrieves the first 15 rows

select emp_name, salary
from employee
where rownum <=15


if you want to retrieve data between row number 10 and row number 15
then it should be in the following way

select emp_name, salary
from
(select rownum r ,emp_name, salary
From employee )
Where r >=10 and r<=15

Wednesday, March 4, 2009

Report image

How to add image to RDLC report

1st step: open your RDLC report add image from report items to your report.

2nd step: Report main menu select REPORT then Embedded Images click new image then select the image you would like to add.

3rd step: go to image properties Source select Embedded.

4th step: go to image properties Value you will find the image name you just embedded, select it.

Now you can see the image inside the report

Tuesday, March 3, 2009

Field format

Replace null values with 0 inside the RDLC report

The following statement replaces the null value with 0 else it keeps the default value
place the code inside the field expression

=iif(Parameters!emp_salary.Value like "",0,Parameters!emp_salary.Value)

Aslo you can replace a specific string with another one
For example if the string begin with “REJ” replace it with “Rejected”

=iif( left(Fields!EMP_ENROLLMENT.Value,3) like "REJ","Rejected",Fields!EMP_ENROLLMENT.Value)

Monday, March 2, 2009

Connection string

Create Oracle connection string using APP.CONFIG file

<_connectionstrings>

< name="CONN_NAME" connectionstring="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.250.10.10)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SID=SIDNAME)));User Id=username;Password=password">

< /connectionStrings >


Second step.
open the connection string

Imports Microsoft.VisualBasic
Imports System.Configuration
Imports System.Data
Imports System.Data.OracleClient
Imports System.Exception


Dim conn As OracleConnection

Try

conn = New OracleConnection(ConfigurationManager.ConnectionStrings("CONN_NAME").ConnectionString)

Catch ex As Exception
Throw ex
Finally
conn.Dispose()
End Try