Sql server “错误”的含义是什么;必须声明标量变量“@”;在.NET内核中

Sql server “错误”的含义是什么;必须声明标量变量“@”;在.NET内核中,sql-server,asp.net-core,dapper,Sql Server,Asp.net Core,Dapper,我不熟悉.NET核心;我尝试在wwwroot文件夹中保存图像,并使用Dapper将文件名和路径保存到SQL Server数据库 public async Task<string> WriteFile(IFormFile file) { String fileName; try { var extension = "." + file.FileName.Split('.')[file.FileName.Split

我不熟悉.NET核心;我尝试在wwwroot文件夹中保存图像,并使用Dapper将文件名和路径保存到SQL Server数据库

public async Task<string> WriteFile(IFormFile file)
{
        String fileName;

        try
        {
            var extension = "." + file.FileName.Split('.')[file.FileName.Split('.').Length - 1];
            fileName = Guid.NewGuid().ToString() + extension; 
            var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\s", fileName);

            using (var bits = new FileStream(path, FileMode.Create))
            {
                await file.CopyToAsync(bits);
            }

            Image image = new Image(fileName,path);

            toDb(image);
        }
        catch (Exception e)
        {
            return e.Message;
        }

        return fileName;
}

public void toDb(Image image)
{
        string fileName = image.fileName;
        string path = image.path;

        using (IDbConnection dbConnection = Connection)
        {
            string sQuery = "INSERT INTO images(title, dir)" + "VALUES(@fileName, @path)";

            dbConnection.Open();
            dbConnection.Execute(sQuery,image);
        }
    }
}
公共异步任务写入文件(ifformfile)
{
字符串文件名;
尝试
{
var extension=“.”+file.FileName.Split('..)[file.FileName.Split('..).Length-1];
fileName=Guid.NewGuid().ToString()+扩展名;
var path=path.Combine(Directory.GetCurrentDirectory(),“wwwroot\\s”,文件名);
使用(var bits=newfilestream(路径,FileMode.Create))
{
等待文件.CopyToAsync(位);
}
图像=新图像(文件名、路径);
toDb(图像);
}
捕获(例外e)
{
返回e.消息;
}
返回文件名;
}
公共无效toDb(图像)
{
字符串文件名=image.fileName;
字符串路径=image.path;
使用(IDbConnection dbConnection=Connection)
{
字符串sQuery=“插入图像(标题,目录)”+“值(@fileName,@path)”;
dbConnection.Open();
dbConnection.Execute(sQuery,image);
}
}
}

这是错误的还是我如何用dapper修复此错误?

您错误地调用了dapper命令

当执行的命令无法找到
@fileName、@path
参数时,会发生此错误

必须使用匿名类传递参数名


参考

thank you的可能副本,但仍会出现相同的错误
dbConnection.Execute(sQuery, new { fileName = filename, path = path });
dbConnection.Execute(sQuery, new { fileName = image.fileName, path = image.path});