Tuesday, April 7, 2009

ListBox Selected Values

Listbox selected values string separated with “,”

Dim li As ListItem
Dim x As Integer = 0
Dim Strv As String

For Each li In LB_users.Items
If li.Selected = True Then
strv = li.Value + "," + txt_users.Text
strv = strv.Remove(strv.Length - 1)

End If

Next

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

Friday, February 27, 2009

Search Selected items

How to search for selected items in a drop down list or compo box

The selected items string should be in the following format
(first item,second item,third item,….)

Then you can use the SQL (IN clause) to retrieve the data
For some reason in ORACLE SQL, you should make the select statement as string to make it work else you will get no thing while if you are using sql server you don’t need to do that

See the following stored procedure

CREATE OR REPLACE PROCEDURE SP_Search_Emp(
ESTATUS IN VARCHAR2,ETYPE IN VARCHAR2,CUR_E_STATUS_TYPE OUT SYS_REFCURSOR )
AS
STR_ESTATUS VARCHAR2(9000);
STR_ETYPE VARCHAR2(9000);
CS VARCHAR2 (15000);

BEGIN

Select ''''Replace(ESTATUS,',',''',''')'''' into STR_ESTATUS from dual;
Select ''''Replace(ETYPE,',',''',''')'''' into STR_ETYPE from dual;

cs:='SELECT e.emp_id,e.emp_name,e.emp_address,e.emp_salary,e.emp_status,e.emp_type

FROM Emp_table e

WHERE emp_Status IN';
cs := cs '('upper(STR_ESTATUS)') AND emp_type IN (' str_etype')
)';

open cur_E_status_type for cs;
END SP_Search_Emp;

Ref Cursor

Ref cursor is one of the most powerful ways to return stored procedures query results from oracle database.
The following example shows how to use oracle ref cursor .


CREATE OR REPLACE PROCEDURE SP_EMP (CUR_EMP OUT SYS_REFCURSOR) AS

BEGIN
OPEN CUR_EMP FOR
SELECT EMP_FNAME, EMP_LNAME, EMP_DATA
FROM EMPLOYEE

Thursday, February 26, 2009

Date Interval

Today I am going to show you how to list the months and years between two dates interval using Oracle SQL

Select distinct to_char(create_date,'MON-yyyy')as Create_Date from
(
SELECT TO_DATE('10/01/2008', 'MM/dd/YYYY') + rownum as create_date
FROM all_objects
WHERE TO_DATE('10/01/2008', 'MM/dd/YYYY') + rownum <= TO_DATE(to_char(sysdate,'mm/dd/yyyy'),'MM/dd/YYYY') )


Result :

OCT-2008
NOV-2008
DEC-2008
JAN-2009
FEB-2009

Wednesday, February 25, 2009

Control file

Control file to load data form text file to oracle database table

LOAD DATA
INFILE 'C:\CTRFILE\TnxFile.dat'
BADFILE 'C:\CTRFILE\TnxFile.bad'
DISCARDFILE 'C:\CTRFILE\TnxFile.dsc'
APPEND
INTO TABLE "Employee_data"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(
EMP_Number position (,) char,
EMP_NAME position(,) char,
EMP_ADDRESS (,)char
)

Oracle spool

Example1 :
Spool data from oracle to text file also you can add title to the text file .


set linesize 50;
set echo off;
set pagesize 9999;
set newpage none;
set heading on;
set recsep off;

spool c:\Data\FileName.txt ;

TTITLE left 'BEX Approved Batch sheets'; -- /* Add title to the text file*/
column c1 heading "emp_id" format a5
column c2 heading "emp_name" format a25
column c3 heading "emp_salary" format $9,999,990.99

SELECT emp_id c1,
emp_name c2,
emp_salary c3
From employee where (emp_salary >=60000)
spool off;

Example 2:
Spool data from oracle to text file and name the file with date and time of data spool

set linesize 50;
set echo off;
set pagesize 9999;
set newpage none;
set heading on;
set recsep off;

col sys_date new_value curr_date;
select 'c:\data\'to_char(sysdate,'yyyy_ddmon_hh24_miss')'.txt' sys_date from dual;
spool &curr_date;

column c1 heading "emp_id" format a5
column c2 heading "emp_name" format a25
column c3 heading "emp_salary" format $9,999,990.99

SELECT emp_id c1,
emp_name c2,
emp_salary c3
From employee where (emp_salary >=60000)
spool off;