【求助】上传图片到数据库的问题

yoobj 2003-10-17 04:51:20
Stream imgdatastream = File1.PostedFile.InputStream;<-----------此行报错
int imgdatalen = File1.PostedFile.ContentLength;
string imgtype = File1.PostedFile.ContentType;
byte[] imgdata = new byte[imgdatalen];
报错提示:Object reference not set to an instance of an object.
...全文
48 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yourbj 2003-10-28
  • 打赏
  • 举报
回复
把html控件做为服务器端控件试试
LighBlade 2003-10-28
  • 打赏
  • 举报
回复
是不是没有把控件作为服务器控件使用,或者是缺少命名空间的引用?
yoobj 2003-10-27
  • 打赏
  • 举报
回复
怎么解决?
yoobj 2003-10-27
  • 打赏
  • 举报
回复
原因查到了。只要我一使用html控件就报这个错误。
未将对象引用设置到对象的实例。
123456754321 2003-10-25
  • 打赏
  • 举报
回复
int FileLength = UP_FILE.PostedFile.ContentLength;
//string imagefieldname="Picture";
Stream StreamObject = UP_FILE.PostedFile.InputStream;
string imgtype = UP_FILE.PostedFile.ContentType;



string strTableName="ImageStore";
// string[] strColNames={"ImageID","ImageContentType","ImageDescription","ImageSize"};
// object[] objColValues={105,imgtype,"sgdfsdgsasfdaf",FileLength};
string[] strColNames={"ImageID","ImageContentType","ImageDescription","Imagechar","nRoomUseArea","cUnitKind","sFoundYear","cIfLab"};
object[] objColValues={207,imgtype,"sgdfsdgsasfdaf","2","123","1","2003-08","1"};
string imgColName="Picture";
if (FileLength==0)
{
txtMessage.Text = "<b>请你选择你要上传的文件</b>";

}
else
{

bool bl=aaa.InsertRecordIncludeImage(strTableName, strColNames,objColValues,imgColName,FileLength,StreamObject);
txtMessage.Text = bl.ToString();}
yoobj 2003-10-24
  • 打赏
  • 举报
回复
up
yoobj 2003-10-23
  • 打赏
  • 举报
回复
不行。
yoobj 2003-10-23
  • 打赏
  • 举报
回复
已经加上去了。
2002pine 2003-10-21
  • 打赏
  • 举报
回复
在form标记上加上encType="multipart/form-data"看行不行
<form id="Form1" method="post" runat="server" encType="multipart/form-data">
yourbj 2003-10-21
  • 打赏
  • 举报
回复
'加上这个
Stream imgdatastream = new Stream();
'再把这行的Stream 去了
imgdatastream = File1.PostedFile.InputStream;<-----------此行报错

int imgdatalen = File1.PostedFile.ContentLength;
string imgtype = File1.PostedFile.ContentType;
byte[] imgdata = new byte[imgdatalen];
yoobj 2003-10-21
  • 打赏
  • 举报
回复
up
godliu521 2003-10-17
  • 打赏
  • 举报
回复
Stream要实力化
要new一下

110,531

社区成员

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

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

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