【发布时间】:2012-01-12 23:25:57
【问题描述】:
可能重复:
“Parameter not valid” exception loading System.Drawing.Image
我在数据库中插入一张图片。
这是我的代码
public class ImageUtils
{
const int sizeThumb = 69;
public static int uploadImage(int memberid, Image thumbimage)
{
MemoryStream stream = new MemoryStream();
thumbimage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] thumbbytes = stream.ToArray();
//int length = Convert.ToInt32(data.Length);
//byte[] thumbimage = new byte[length];
//data.Read(thumbimage, 0, length);
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["FMMImages"].ConnectionString);
SqlCommand command = new SqlCommand("update Images_temp set thumbimage = @thumbimage where memberid=@memberid", connection);
SqlParameter param0 = new SqlParameter("@thumbimage", SqlDbType.Image);
param0.Value = thumbbytes;
command.Parameters.Add(param0);
connection.Open();
object result = command.ExecuteScalar();
connection.Close();
if (result != null)
{
return System.Convert.ToInt32(result);
}
else
{
return 0;
}
}
aspx.cs 我在哪里调用 uploadimage 图像裁剪水印图像 ......
ImageUtils.uploadImage(memberid, CroppedWaterMarkImage);
上传图片功能出错:
MemoryStream stream = new MemoryStream();
thumbimage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] thumbbytes = stream.ToArray();
System.ArgumentException:参数无效。
谢谢 孙
【问题讨论】:
-
如果你调试,它会停在哪一行?
-
如果 C# 数据库库与 Java 库类似,那么您不会将“thumbimage”传递给
SqlParameter构造函数而不是“@thumbimage”吗?此外,您似乎没有为“@memberid”参数设置值。
标签: c#