0

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?)

2 Answers 2

3

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();
Sign up to request clarification or add additional context in comments.

3 Comments

It works. Thanks for the answer. I will accept it after few minutes
great, happy coding
You are not even going to mention the glaring SQL injection problem in the code?
0

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.