请问如何显示和上传System.Object类型的图片??

anantnt203120 2004-07-05 10:39:56
在Web Service中已经定义了图片属性为System.Object类型,请问如何实现将.jpg等格式的图片上传保存到数据库中?
求救!
...全文
100 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
anantnt203120 2004-07-13
  • 打赏
  • 举报
回复
top
Piyongcai 2004-07-06
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=6381BD5F-51F3-4339-4239-1328564A1B2A
anantnt203120 2004-07-06
  • 打赏
  • 举报
回复
但是读取时发现返回的Picture为空,请问如何保存这种Object类型的图片呢?
anantnt203120 2004-07-06
  • 打赏
  • 举报
回复
谢谢各位,但是我的问题是:
因为Web Service是已经定义好的,Picture参数为Object类型。
我已经试过将图片转换为二进制数据做参数传入,保存时没发生错误,(如果直接将PictureBox.Image做为Objcet类型保存,发生“保存XML文件错误”)但是独特、
magicangella 2004-07-06
  • 打赏
  • 举报
回复
//存储图片
private void ins_pic_sql()
{

System.Data.SqlClient.SqlConnection myconn=new SqlConnection("User Id=sa;password=;Data Source=GONGJ;initial catalog=test_1");
myconn.Open();
SqlCommand comm=new SqlCommand();
comm.Connection=myconn;
// comm.CommandType=CommandType.StoredProcedure;
comm.CommandText="insert into userdetail(userid,username,userpict) values(@userid,@username,@userpict)";

System.IO.MemoryStream mstream=new System.IO.MemoryStream();

pictBox1.Image.Save(mstream,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] barray=new byte[Convert.ToInt32(mstream.Length)];
mstream.Read(barray,0,Convert.ToInt32(mstream.Length));

SqlParameter sp=new SqlParameter("@userpict",System.Data.SqlDbType.Image,Convert.ToInt32(mstream.Length));
sp.Value=barray;
comm.Parameters.Add(sp);

sp=new SqlParameter("@userid",System.Data.SqlDbType.Int);
sp.Value=1;
comm.Parameters.Add(sp);

sp=new SqlParameter("@username",System.Data.SqlDbType.VarChar);
sp.Value=pictBox1.Image.GetType().ToString();
comm.Parameters.Add(sp);

comm.ExecuteNonQuery();
myconn.Close();

}
通过测试
CMIC 2004-07-05
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=6381BD5F-51F3-4339-4239-1328564A1B2A
melonlee 2004-07-05
  • 打赏
  • 举报
回复
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506
anantnt203120 2004-07-05
  • 打赏
  • 举报
回复
谢谢,我要保存的图片在Web Service端已经定义了保存为object类型,请问如何显示和上传图片,本系统是C#的Windows应用程序。

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧