-1

here is my c# code on a button click:

                Int32 fileLen;

            fileLen = uplImage.PostedFile.ContentLength;


            Byte[] input = new Byte[fileLen];

            myStream = uplImage.FileContent;

            myStream.Read(input, 0, fileLen);

            DALBio bio = new DALBio();
            bio.PlayerID = Session["playerID"].ToString();
            bio.Pending = 'Y';
            bio.Photo = input;
            DALBio.insertImage(bio);

here is my c# code to call a stored proc

public static bool insertImage(DALBio bio)
{
    string sql = string.Format("EXECUTE insertPlayerImage @playerID = '{0}', @profileImage = '{1}', @pending = '{2}'", bio.playerID, bio.Photo, bio.pending);

    SqlCommand insertPhoto = new SqlCommand(sql, baseballConnection);

    try
    {
        baseballConnection.Open();
        insertPhoto.ExecuteNonQuery();
        return true;
    }
    catch
    {
        return false;
    }
    finally
    {
        baseballConnection.Close();
    }
}

i get the following error: Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

so i tried to alter my stored proc to:

ALTER PROCEDURE insertPlayerImage @playerID varchar(9), @profileImage varchar(max), @pending char(1)
AS

CONVERT(varbinary(max), @profileImage)

INSERT INTO PlayerImage(
playerID,profileImage, pending)
VALUES(
@playerID, @profileImage, @pending)
GO

and it doesnt like the convert line. really not sure what to do.

dwarf
  • 445
  • 2
  • 9
  • 23
  • 1
    **Duplicate** of [SQL CONVERT from varbinary to varchar](http://stackoverflow.com/questions/16571892/sql-convert-from-varbinary-to-varchar) – marc_s May 15 '13 at 18:38

1 Answers1

-1

Try this :-

alter PROCEDURE insertPlayerImage (@playerID varchar(9), @profileImage varchar(max), @pending char(1))

AS

SET @profileImage = CONVERT(varbinary(max), @profileImage)

HSQL
  • 74
  • 2