-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) –