You can use this:

try {
Employee employee = _empDataSource.
QueryForObject<Participant>(Constants.GET_EMP_COUNT,
employeeParameters );

return ( (employee==null)? 0: employee.employeeCount);
}

Greetings!


On Wed, Jun 3, 2009 at 1:40 PM, sanjeev40084 <sanjeev40...@hotmail.com>wrote:

>
> In my sqlMap, i have a code that calls stored procedure and returns count
> of
> employee. Anytime employee count is null, my programs seems to fail.
>
> Here is the code.
>
> Employee.cs
>
>        int? employeeCount;
>        public int? EmployeeCount
>        {
>            get { return employeeCount; }
>            set { if(value.HasValue)
>                    {
>                        employeeCount = value;
>                    }
>                    else
>                    {
>                        employeeCount = 0;
>                    }
>                }
>        }
>
>
> SqlMap.xml
>
> <alias>
>   <typeAlias alias="Employee" type="Test.Domain.Employee, Test.Domain"/>
>   <typeAlias alias="EmployeeParameters"
> type="Test.Domain.EmployeeParameters, Test.Domain"/>
> </alias>
>
> <parameterMap id ="testParameters" class="EmployeeParameters">
>                  <parameter property="EmployeeID"  column="employeeId"/>
>                  <parameter property="Year" column="year"/>
> </parameterMap>
>
> <resultMap id="employeeMap"  class="Employee">
>       <result property="EmployeeCount"   column="totalCount"/>
> </resultMap>
>
> <procedure id="GetEmployeeCount" parameterMap="testParameters"  resultMap
> ="employeeMap">
>                  test..GetTotalEmployeeCount
> </procedure>
>
>
> Now this is where it is being called:
>
> public int GetEmpCount(EmployeeParameters employeeParameters)
>        {
>            try
>            {
>                Employee employee = new Employee();
>                employee
> =_empDataSource.QueryForObject<Participant>(Constants.GET_EMP_COUNT,
> employeeParameters );
>
>                int? empCount = employee.employeeCount  <--When the employee
> Count is null, employee = null, thus this line breaks)
>
>                if(empCount  > 0)
>                {
>                    return (int) empCount;
>                }
>                return 0;
>            }
>            catch (Exception ex)
>            {
>                throw new Exception("Unable to retrieve employee counts",
> ex);
>            }
>        }
>
> any suggestions?
>
>
> --
> View this message in context:
> http://www.nabble.com/Error-while-query-returns-null-value--tp23855885p23855885.html
> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>
>

Reply via email to