Hi, currently i'm able to save an image that I have draw into SQL but I would like to knw if it is possible to update new draw picture to replace the old picture?

how can i modify this code in order for it to save instead of create another new image?

Public Sub SaveByteArray(ByVal ByteArr() As Byte, ByVal patientIC As String)
        '
        Dim mySQL As String
        Dim cmdAdd4 As SqlCommand
        Dim oVarCharParam As SqlParameter
        Dim oBLOBParam As SqlParameter

        Try
            connAdd.Open()
            ' Insert statement
            ' Notice that @BLOBValue is a placeholder for the actual data
            mySQL = "INSERT INTO image (patientIC, picture) VALUES (@IDValue, @BLOBValue)"
            ' Create a command object
            cmdAdd4 = connAdd.CreateCommand()
            ' Set SQL statement
            cmdAdd4.CommandText = mySQL
            ' Create a command parameter
            oVarCharParam = New SqlParameter("@IDValue", SqlDbType.VarChar, _
               50, ParameterDirection.Input.ToString)
            ' Set the actual data
            oVarCharParam.Value = patientIC
            ' Add this parameter to the command
            cmdAdd4.Parameters.Add(oVarCharParam)
            ' Create a command parameter
            oBLOBParam = New SqlParameter("@BLOBValue", SqlDbType.Binary, _
              ByteArr.Length, ParameterDirection.Input.ToString)
            ' Finally, set the actual data
            oBLOBParam.Value = ByteArr
            ' Add this parameter to the command
            cmdAdd4.Parameters.Add(oBLOBParam)
            ' Execute SQL statement
            cmdAdd4.ExecuteNonQuery()
            ' Close the connection
        Catch ex As Exception
        End Try

    End Sub

Thanks..

Change this line:

mySQL = "INSERT INTO image (patientIC, picture) VALUES (@IDValue, @BLOBValue)"

To:

mySQL = "Update image Set picture = @BLOBValue Where patientIC =  @IDValue"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.