5
Follows code:
var file = Request.Files;
var list = new List<byte[]>();
for (int i = 0; i < 4; i++)
{
if (file.Count > i)
{
list.Add(ConvertTo.Bytes(file[i]));
continue;
}
list.Add(null);
}
int count = ctx.Database.ExecuteSqlCommand(
$"UPDATE dbo.Table " +
$"SET Imagem1 = @imagem1, Imagem2 = @imagem2, Imagem3 = @imagem3, Imagem4 = @imagem4 " +
$"WHERE id = {Id}",
new SqlParameter("imagem1", list[0] ?? null),
new SqlParameter("imagem2", list[1] ?? null),
new SqlParameter("imagem3", list[2] ?? null),
new SqlParameter("imagem4", list[3] ?? null));
Error:
The parameterized query '(@imagem1 varbinary(max) ,@imagem2 nvarchar(4000),@imagem3 nvarc' expects parameter '@imagem2', other than was provided.
This error happens when user chooses only one image.
Some solution ?
debugging the contents of the list[1] ?
– Thiago Loureiro
if Voce chooses 2 images gives error in 3?
– Thiago Loureiro
@imagem1 varbinary(max) ,@imagem2 nvarchar(4000),@imagem3 nvarc ?????? all parameters are varbinary? not understood now.. the first seems to be different from the others..
– Thiago Loureiro
yes.. but it’s strange that he says that the types are different... in his database as it is ?
– Thiago Loureiro
guy tries to put this: in his Parameters new Sqlparameter("imagem1", System.Data.Sqldbtype.Varbinary). Value = list[0];
– Thiago Loureiro
Let’s go continue this discussion in chat.
– Thiago Loureiro
@Matheusmiranda You need to use
SqlBinary.Null
– Jéf Bueno
That’s right @LINQ, the problem has been solved, thank you.
– Matheus Miranda