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`

Recommended Answers

All 3 Replies

You can't concatenate an array. To see how to insert binary data you can look at this code snippet. The example uses a PDF.

"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 & "'"

Thanks Jim

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.