I am trying to update pdf file to sql but getting error (line 17) as operator '&' is not defined for types 'string' and '1-dimensional array of byte' on beow line

cmd.CommandText = "UPDATE PDC_CHQ_IN_HAND set PDC_CHQ_IN_HAND.PDF='" & data & "'WHERE PDC_CHQ_IN_HAND.RefNo='" & TxtRefNo.Text & "'"

  • my code is*

    Private Sub ButPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButPDF.Click
    Try

        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    
            Dim Img As String = OpenFileDialog1.FileName.ToString
            Dim finfo As New FileInfo(Img)
            Dim numbytes As Long = finfo.Length
    
            Dim fstream As New FileStream(Img, FileMode.Open, FileAccess.Read)
            Dim br As New BinaryReader(fstream)
            Dim data As Byte() = br.ReadBytes(CInt(numbytes))
            MsgBox(Convert.ToString(data.Length))
            br.Close()
            fstream.Close()
    
            Call Connect()
            Dim cmd As New SqlClient.SqlCommand
            cmd.Connection = CnCommon
            cmd.CommandText = "UPDATE PDC_CHQ_IN_HAND set PDC_CHQ_IN_HAND.PDF='" & data & "'," _
             & "'WHERE PDC_CHQ_IN_HAND.RefNo='" & TxtRefNo.Text & "'"
            cmd.ExecuteNonQuery()
    
            MessageBox.Show("Image has been saved", "Save", MessageBoxButtons.OK)
            CnCommon.Close()
            CnCommon.Dispose()
    
        End If
    Catch ex As Exception
    
    End Try
    

    End Sub`

Edited 1 Year Ago by PM312

"UPDATE PDC_CHQ_IN_HAND set PDC_CHQ_IN_HAND.PDF='" & data & "'," _
& "'WHERE PDC_CHQ_IN_HAND.RefNo='" & TxtRefNo.Text & "'"

From my opinion the SQL Statement is in incorrect formation. How could you use a , Comma and a ' SingleQuatation Charactor before Where Clause. And also an & Ampersand charactor before it.

The Statement should be

 "UPDATE PDC_CHQ_IN_HAND set PDC_CHQ_IN_HAND.PDF='" & data & _
          "' WHERE PDC_CHQ_IN_HAND.RefNo='" & TxtRefNo.Text & "'"

Edited 1 Year Ago by Shark_1

This question has already been answered. Start a new discussion instead.