I have a query which retuns a string value as the output. But shows an error in the return. I dont know how to fix it. Here i have added my query.
public string detailsRemarksGet(string ddlValue)
{
string strQuery = @"select r.remarks
from [A_MASTER] m, [A_REMARKS] r
where m.A_REF_NO=r.A_REF_NO
and r.A_REF_NO='"+ ddlValue +"' and DEPT='POS' ";
return SqlHelper.ExecuteScalar(strConnStringAppeal, CommandType.Text, strQuery);
}
Here is mky code of .cs
public string detailsRemarks(string ddlValue)
{
string remarks= db.detailsRemarksGet(ddlValue);
return remarks;
}
In the error list i get a message as follows
Error 2 Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Sql query return object
type, you need to cast that as string
. So cast as string
using ToString()
method in return statement
return SqlHelper.ExecuteScalar(strConnStringAppeal, CommandType.Text, strQuery).ToString();
Just convert your return type to String , because your method name db.detailsRemarksGet will return you an object and your detailsRemarks method return type is string.
public string detailsRemarks(string ddlValue)
{
string remarks= Convert.ToString(db.detailsRemarksGet(ddlValue));
return remarks;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.