您的位置:程序门 -> .net技术 -> c#



上传图片时选择图片后, 提示缓冲不能为空,buffer


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


上传图片时选择图片后, 提示缓冲不能为空,buffer
发表于:2007-01-31 10:30:37 楼主
各位高手哥哥好 小弟弟遇到这样的问题
我想在软件上,上传图片,可是当我选择图片后 却提示我 "缓冲不能为空,参数buffer"    请问该怎么修改啊 谢谢了 我的代码是这样的
sqldatareader   sdr   =   null;
        filestream   fsread   =   null;
filestream   fswrite   =   null;
binaryreader   br   =   null;
binarywriter   bw   =   null;
byte[]   by   =   null;
int   num   =   0;

this.openfiledialog1   =   new   openfiledialog();
this.openfiledialog1.filter   =   "all   files   (*.*) ¦*.* ¦image   files   (*.jpg,   *.bmp,   *.gif) ¦*.jpg;   *.bmp;   *.gif ";
if   (this.openfiledialog1.showdialog()   ==   dialogresult.ok)
{
if(openfiledialog1.filename!= " ")
{
fsread   =   new   filestream(this.openfiledialog1.filename,filemode.open);
br   =   new   binaryreader(fsread);
num=   int.parse(fsread.length.tostring());
br.read(by,0,num);
                conn.open();
strsql= "insert   into   zoffice(照片)values( ' "+by+ " ')   where   报名处名称= ' "+tb11.text.tostring()+ " '   and   姓名= ' "+tb61.text.tostring()+ " ' ";
cmd=new   sqlcommand(strsql,conn);
cmd.EXECutenonquery();
br.close();
fsread.close();
messagebox.show( "添加成功 ");
}

else
messagebox.show( "没有选择照片 ");
                               
}
发表于:2007-01-31 11:10:061楼 得分:0
厄,下面是我程序里面的一段,可以正常运行。
怀疑你是不是漏了
byte[]   buffer   =   new   byte[stream.length];类似的一句话,而且filestream实例化少参数

system.io.filestream   stream   =   new   system.io.filestream(filepath,   system.io.filemode.open,   system.io.fileaccess.read);
byte[]   buffer   =   new   byte[stream.length];
stream.read(buffer,   0,   (int)stream.length);
stream.close();
this.sqlconn.open();
sqlcommand   cmd=new   sqlcommand( "update   notify   set   notifydata=@notifydata   where   notifyid=@notifyid ",this.sqlconn);
cmd.parameters.add( "@notifydata ",sqldbtype.image).value=buffer;
cmd.parameters.add( "@notifyid ",sqldbtype.int).value=notifyid;
cmd.EXECutenonquery();
this.sqlconn.close();
发表于:2007-01-31 11:33:222楼 得分:0
上面的大哥 你的system.io.filestream   stream   =   new   system.io.filestream(filepath,   system.io.filemode.open,   system.io.fileaccess.read);里的 filepath是什么啊 
可以给我一段完整的程序吗 谢谢了
发表于:2007-01-31 11:56:543楼 得分:0
...那个是文件路径阿
发表于:2007-01-31 13:28:014楼 得分:0
大哥,我知道是路径啊 
可是你是怎么设置的嘛 我写在程序就抱错 说找不到名称啊
还有调试的时候出项路径为空 到底怎么的啊
你是怎么初始化和设置路径的 给我看看 好吗 谢谢了 大哥
发表于:2007-01-31 13:31:125楼 得分:0
大哥 可以把你qq留下吗 谢谢了 我的是 491117612
发表于:2007-01-31 19:27:526楼 得分:0
着急等待啊 各位大哥帮帮我吧


快速检索

最新资讯
热门点击