0

I tried but it gives this error

Must declare the scalar variable "@imageid"

controller.cs

    [HttpGet]
    [Route("download/{id:int}")]
    public String Getfiles(int imageid)
    {

        return _ShopDataProvider.DownloadImage(imageid);

    }

class.cs

public String  DownloadImage(int imageid)
    {
        using(IDbConnection dbConnection = Connection)
        {

            string sQuery0 = "SELECT path FROM Shop WHERE ShopId = @imageid";
            dbConnection.Open();
            String Path = dbConnection.QueryFirstOrDefault<String>(sQuery0, new { ShopId = imageid });

            return Path;
        } 
    }

1 Answer 1

2

You're declaring a parameter in your SQL query named @imageid but not providing a value for it. You're providing a value for the parameter @ShopID (new { ShopId = imageid }), which your SQL query doesn't use.

Change new { ShopId = imageid } to new { imageid = imageid }

Please refer to the documentation.

Sign up to request clarification or add additional context in comments.

4 Comments

there are values in my DB error is fixed but return string is null when i changed SELECT path FROM Shop WHERE ShopId = @imageid to Select ShopName ..etc
String Path = dbConnection.QueryFirstOrDefault<String>(sQuery0, new { imageid = 1 }); it return me a values but String Path = dbConnection.QueryFirstOrDefault<String>(sQuery0, new { imageid = imageid }); it doesnt return value
@DulangaHeshan Use a debugger. Look at the value of imageid. Does it have the value you're expecting?
yes thnks i fixed error was [Route("download/{id:int}")] here thank you very much brother

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.