这是我单击按钮时的 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
它不喜欢转换线。真的不知道该怎么办。