Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Quote:
Object of type 'System.Int32' cannot be converted to type 'System.Boolean'.



this is my code

C#
private void SetValues()
    {
        HR.Dal.Controllers.Leave_Request cLeaveReq = new HR.Dal.Controllers.Leave_Request();
        try
        {
            HR.Dal.Model.Leave_Request iLeaveReq = cLeaveReq.Get(Convert.ToInt32(LeaveReqid));
            txtLeaveReqId.Text = iLeaveReq.LEAVE_REQUEST_ID.ToString();
            txtEmpNo.Text=iLeaveReq.EMP_NO;
            txtFromDate.Text=iLeaveReq.FROM_DATE.ToString();
            txtToDate.Text=iLeaveReq.TO_DATE.ToString();
            RequestTypeId.Text=iLeaveReq.REQUEST_TYPE_ID.ToString();
            txtApprovalDate.Text=iLeaveReq.APPROVAL_DATE.ToString();
           txtIsApproved.Text=iLeaveReq.IS_APPROVED.ToString();
                        
        }
        catch (Exception Exp)
        {
            throw Exp;
        }
    }
Posted
Updated 27-Jul-15 19:52pm
v2
Comments
Wendelius 28-Jul-15 3:23am    
When you debug the program, on what line the exception occurs?

1 solution

Most likely cLeaveReq.Get method accepts a boolean parameter and you are passing it an integer Convert.ToInt32(LeaveReqid). You need to change either the method or the call to the method.
 
Share this answer
 
Comments
Meer Wajeed Ali 28-Jul-15 1:52am    
my Get method accept only integer
public HR.Dal.Model.Leave_Request Get(int recordId);
Afzaal Ahmad Zeeshan 28-Jul-15 2:03am    
Wrong, if it would accept integer values then there would have been no problem at all. The problem is with this parameter, that you are casting to integer. It needs to be a boolean.
CPallini 28-Jul-15 2:37am    
Then you have to post some more code, in order to get help.
Meer Wajeed Ali 28-Jul-15 2:44am    
this one is my controllers' class method


public Model.Leave_Request Get(int recordId)
{
Model.Leave_Request iObject = null;
DBManager dbManager = null;
IDataReader iReader = null;
string sql = string.Empty;

try
{
sql = "SELECT LEAVE_REQUEST_ID,EMP_NO,FROM_DATE,TO_DATE,REQUEST_TYPE_ID,APPROVAL_DATE,IS_APPROVED FROM dbo.LEAVE_REQUEST WITH(NOLOCK) WHERE IS_DELETED=0 AND LEAVE_REQUEST_ID= " + recordId;

switch (Constants.DBEngine)
{
case (int)DataProvider.SqlServer:
dbManager = new DBManager();
dbManager.ProviderType = DataProvider.SqlServer;
dbManager.ConnectionString = Constants.ConnectionString;
break;
}
dbManager.Open();
dbManager.Command.CommandTimeout = Constants.CommandTimeOut;
dbManager.Command.CommandText = sql;
dbManager.Command.Connection = dbManager.Connection;
iReader = dbManager.Command.ExecuteReader();
iObject = iReader.SingleOrDefault<model.leave_request>();
}
catch (Exception Exp)
{
throw Exp;
}
finally
{
if (iReader != null)
iReader.Close();
if (dbManager != null)
dbManager.Close();
}
return iObject;
}
Jitesh Hirani 30-Jul-15 2:40am    
In the following line pls try
sql = "SELECT LEAVE_REQUEST_ID,EMP_NO,FROM_DATE,TO_DATE,REQUEST_TYPE_ID,APPROVAL_DATE,IS_APPROVED FROM dbo.LEAVE_REQUEST WITH(NOLOCK) WHERE IS_DELETED=Cast(0 as BIT) AND LEAVE_REQUEST_ID= " + recordId;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900