日期:2014-05-19  浏览次数:21101 次

上传图片的代码,是哪错了?
上传图片的代码,我不知道是哪错了?
HttpPostedFile   upfile   =   File1.PostedFile;
filelen=upfile.ContentLength;
if(filelen==0)
{
txtmess.Text= " <b> 请选择你要上传的图片! </b> ";

}
else
{
                                Byte[]   file1   =new   byte[filelen];
                                Stream   stream1=upfile.InputStream;
stream1.Read(file1,0,filelen);

                                string   str= "Provider=Microsoft.Jet.OleDb.4.0; "+@ "Data   Source= "+Server.MapPath( "../test.mdb ");
OleDbConnection   conn2=new   OleDbConnection(str);
conn2.Open();
string   sql2= "insert   into   ImageStore(imadata,imasize,imadescription)   values(@imadata,@imasize,@imadescription) ";
OleDbCommand   comm2=new   OleDbCommand(sql2,conn2);
                                comm2.Parameters.Add( "@imadata ",file1);
                              //comm2.Parameters.Add( "@imacontenttype ",System.Data.OleDb.OleDbType.VarChar,50,upfile.ContentType);
                                comm2.Parameters.Add( "@imadescription ",System.Data.OleDb.OleDbType.VarChar,200,description.Text);
                                comm2.Parameters.Add( "@imasize ",System.Data.OleDb.OleDbType.BigInt,8).Value=upfile.ContentLength;

comm2.CommandType=CommandType.Text;
comm2.ExecuteNonQuery();
conn2.Close();
txtmess.Text   =   " <p> <b> OK!你已经成功上传你的图片 </b> ";
}
说明:   执行当前   Web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。  

异常详细信息:   System.Data.OleDb.OleDbException:   参数   @imasize   没有默认值。

源错误:  


行   114:
行   115: comm2.CommandType=CommandType.Text;
行   116: comm2.ExecuteNonQuery();
行   117: conn2.Close();

 
请大家帮我看一下,谢谢!


------解决方案--------------------
string sql2= "insert into ImageStore(imadata,imasize,imadescription) values(@imadata,@imasize,@imadescription) ";

这里有问题,你看一下你的@imasize是否获到了值,或是库中有没有设置默认值。
------解决方案--------------------
( "@imasize ",System.Data.OleDb.OleDbType.Binary,8).Value=upfile.ContentLength;
改为:( "@imasize ",System.Data.OleDb.OleDbType.Binary,8).Value=upfile