运营商“&”未定义类型“字符串”和“图像”

时间:2016-05-31 09:41:00

标签: sql vb.net

美好的一天,

我想将图像存储在数据库中,但我无法实现它。我收到错误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

1 个答案:

答案 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