美好的一天,
我想将图像存储在数据库中,但我无法实现它。我收到错误operator '&' is not defined for types 'string' and 'image'
请帮忙。
Function InsertTask(ByVal IdTask As Integer, ByVal NameImage As String, ByVal PImage As Image)
Dim MessageExit As String = "Great, the picture is Saved"
Try
cmd = New SqlCommand("INSERT INTO ALBUMES(IDTASKD, NAMEIMG, P_IMAGE) VALUES('" & IdTask & "','" & NameImage & "','" & PImage & "')", conex)
Catch ex As Exception
MessageExit = ":( Error:" + ex.ToString
End Try
Return MessageExit
End Function
答案 0 :(得分:2)
我建议您使用参数来使用SqlDbType
,并且还要避免SQL注入,如下所示:
cmd = New SqlCommand("INSERT INTO ALBUMES(IDTASKD, NAMEIMG, P_IMAGE) " &
"VALUES(@IDTASKD,@NAMEIMG,@P_IMAGE)", conex)
cmd.Parameters.Add("@IDTASKD", SqlDbType.Int).Value = IdTask
cmd.Parameters.Add("@NAMEIMG", SqlDbType.NVarChar, 50).Value = NameImage
cmd.Parameters.Add("@P_IMAGE", SqlDbType.Image).Value = PImage