insert image in sql

  • i have a problem to insert type image in sql with front end vb 6. this is script :

    Private Sub CmdSave_Click()

        Dim ADOCmd As New ADODB.Command

        Dim ADORs As New ADODB.Recordset

        Set mstream = New ADODB.Stream

       

        With ADOCmd

            .ActiveConnection = sDSN

            .CommandText = "sp_update_photo"         .CommandType = adCmdStoredProc

            .Parameters("@ID_Card") = MIdCard.Text

            mstream.Type = adTypeBinary

            mstream.Open

            mstream.LoadFromFile strFlNm

            .Parameters("@Photo") = mstream.Read

            Set ADORs = .Execute

        End With

        Set ADORs = Nothing

        ADOCmd.ActiveConnection = Nothing

    End Sub

    Run-time error '-2147217833' [Microsoft][ODBC SQL Server Driver]String data, Right Truncation

  • The problem is probably in the procedure 'sp_update_photo' that you are calling!

  • CREATE PROCEDURE [DBO].[SP_UDT_FOTO]

    (

      @ID_Card varchar(7),

      @Foto image

    )

     AS

    UPDATE T_Employee

    SET Photo = @Photo

    WHERE ID_Card = @Id_Card

    GO

    so, what can i do to solve this problem ??

     

     

     

  • to me it appears that the "MIdCard.Text" is causing the error - are you sure this is not causing the problem - what is the datalength of this field ?! what is the difference between the first and second stored procedures that you have posted ?! ie - "sp_udt_foto" and "sp_update_photo" ?!?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • CREATE PROCEDURE [DBO].[sp_update_photo]

    (

      @ID_Card varchar(7),

      @Photo image

    )

     AS

    UPDATE T_Employee

    SET Photo = @Photo

    WHERE ID_Card = @Id_Card

    GO

    so, what can i do to solve this problem ??

  • Right, what I was getting at was ODBC is generating this error because the procedure is returning the truncation when the first paramerter is passed. So, is the text being passed to @ID_Card bigger than 7 characters. If so, check data vaidation in ui (.text can be greater than 7) to proc param (varchar(7)) to table data type (?).

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply