How to insert or update picture in db2 using vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • welwel
    New Member
    • Mar 2014
    • 1

    How to insert or update picture in db2 using vb6

    How to insert or update picture in db2 using vb6

    i have succeded to insert into text & number fileds
    in the records but the Blob filed cannot be inserted
    and have the following message type mismatch

    and here is my code

    Code:
       '-----------------------------------for adding a new record in pictures_file-------------------
    
    Dim S As String
    Dim ne1 As Integer
    
    Dim ne2 As Byte
    Dim nam As String
    Dim Fields(6) As String
    Dim values(6) As String
    Dim PIC_val As PictureTypeConstants
    Dim PIC_SAV As String
    
    Dim PIC1_VAL As LoadPictureConstants
    
    ne1 = Text5.Text
    ne2 = Text6.Text
    nam = Text7.Text
    
    Fields(0) = "PIC_ID_CODE"
    Fields(1) = "PIC_SER"
    Fields(2) = "PIC_NAME"
    Fields(3) = "PIC_PATH"
    Fields(4) = "PIC_TILED"
    Fields(5) = "PHOTO_FORMAT"
    Fields(6) = "PICTURE"
    'PIC_SAV = Picture
    
    
    values(0) = Text5.Text
    values(1) = Text6.Text
    values(2) = "'" & Text7.Text & "'"
    values(3) = "'" & Text2.Text & "'"
    values(4) = "'" & Text4.Text & "'"
    values(5) = "'" & Text3.Text & "'"
    PIC1_VAL = Picture2.Picture
    PIC_SAV = PIC1_VAL
    
    S = ("insert into PICTURES_FILE(" & Fields(0) & "," & Fields(1) & "," & Fields(2) & "," & Fields(3) & "," & Fields(4) & "," & Fields(5) & "," & Fields(6) & " )VALUES(" & values(0) & "," & values(1) & "," & values(2) & "," & values(3) & "," & values(4) & "," & values(5) & "," & PIC1_VAL & ")")
    
    
    Dim conn As ADODB.Connection
     Set conn = New ADODB.Connection
     conn.ConnectionString = "Provider=ibmdadb2;Driver={IBM DB2 ODBC DRIVER};Database=ARCIV_DB;Hostname=COMPANY-C97BE4D;port=50000;Protocol=TCPIP;Uid=db2admin;Pwd=db2admin"
     conn.CursorLocation = adUseClient
                 conn.Open
    conn.Execute S
    conn.close
    Last edited by Rabbit; Mar 19 '14, 03:29 PM. Reason: Please use [code] and [/code] when posting code or formatted data.
  • Honduras2811
    New Member
    • Apr 2014
    • 21

    #2
    Are you sure that you are getting the error message from the Blob, or could it be something else?

    The first thing I notice is that ne1 is declared as an Integer, but you are assigning a String to it. I suggest you use:
    Code:
    ne1 = Val(Text5.Text)
    That should also work with ne2.

    However, Values() is declared as an array of strings. So you have two choices. You can either declare ne1 and ne2 as Strings (This would be easiest.), or you can leave them as they are and use Val to assign the .Text values to them, and then use
    Code:
    Values(0) = CStr(ne1)
    Either way, you are still going to have problems if the database expects Values(0) to be an Integer, but what you send it is a String.

    Have you considered using a UDT (User Defined Type) instead of an array of Strings?
    Last edited by Honduras2811; Apr 7 '14, 07:44 AM. Reason: Afterthought

    Comment

    Working...