Save image with procedure.

5 posts, 0 answers
  1. Gadonski
    Gadonski avatar
    2 posts
    Member since:
    Jul 2010

    Posted 24 Sep 2010 Link to this post

    I am using Telerik's ORM...

    This stored procedure does not save the data, it seems to be a problem with the VARBINARY. I am passing a byte[] to it, but then it doesn't work. If I send this parameter as NULL it works.

    "QP_AddCommunity ?, ?, ?, ?, ?, ?", "VARCHAR Name, VARCHAR Description, VARBINARY Picture, INTEGER Owner, INTEGER Venue, INTEGER ID"

    Here is my procedure, which works just fine executing directly on SQLServer.

    USE [redimob]
    GO
     
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[QP_AddCommunity]
        @Name VARCHAR(120),
        @Description VARCHAR(MAX),
        @Picture VARBINARY(MAX),
        @Owner INTEGER,
        @Venue INTEGER,
        @ID INTEGER
          
    AS
    BEGIN
        SET NOCOUNT ON;
      
        IF(SELECT COUNT(*) FROM QT_Community WHERE ID = @ID) = 0
            INSERT INTO QT_Community(Name, [Description], Picture, [Owner], Venue) VALUES(@Name, @Description, @Picture, @Owner, @Venue);
              
        ELSE
            UPDATE QT_Community SET Name = @Name, [Description] = @Description, Picture = @Picture, [Owner] = @Owner, Venue = @Venue WHERE ID = @ID;
              
        SELECT * FROM QT_Community WHERE ID = @@IDENTITY;
              
          
    END


    What am I doing wrong? Isn't VARBINARY a byte[] ?
  2. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 24 Sep 2010 Link to this post

    Hi André,

    Have you tried using the IMAGE sql type instead of VARBINARY?

    I have used both the IMAGE sql type and the VARBINARY(MAX) and they worked like a charm.

    Maybe you should change the parameter when you call the SP from VARBINARY to VARBINARY(MAX)

    Regards

    Henrik
  3. DevCraft banner
  4. Gadonski
    Gadonski avatar
    2 posts
    Member since:
    Jul 2010

    Posted 24 Sep 2010 Link to this post

    Hi Henrik,

    I can't undestand what you are trying to say. Could you elaborate more on your answer?
  5. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 25 Sep 2010 Link to this post

    Hi André,

    Instead of using VARBINARY to hold the binary content, use the IMAGE datatype.

    I think I remember seeing a post once, that VARBINARY was not supported when doing SP's.

    Maybe someone from Telerik can elaborate on this.

    Regards

    Henrik
  6. Ady
    Admin
    Ady avatar
    589 posts

    Posted 29 Sep 2010 Link to this post

    Hello Andre,

     As Henrik rightly pointed out there was a bug when dealing with VARBINARY parameters and stored procedures. This has been fixed now and the fix would be available in the next build that we will soon release.

    Sorry for the inconvenience caused.

    Kind regards,
    Ady
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner