-1
這裏是一個按鈕,點擊我的C#代碼:SQL轉換爲varchar和varbinary用C#
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);
這裏是我的C#代碼來調用存儲過程
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();
}
}
我得到以下錯誤:不允許從數據類型varchar到varbinary(max)的隱式轉換。使用CONVERT函數來運行此查詢。
,所以我想改變我的存儲過程來:
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
和它不一樣的轉換線。真的不知道該怎麼做。
** [從varbinary到varchar的SQL CONVERT]的重複**(http://stackoverflow.com/questions/16571892/sql-convert-from-varbinary-to- VARCHAR) –