"将截断字符串或二进制数据。"错误解决
以下是我的一段代码,要实现图片文件上传到数据库,运行后保错“将截断字符串或二进制数据”,请问如何解决
HttpPostedFile UpFile = UP_FILE.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = UpFile.ContentLength; //记录文件长度
Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UpFile.InputStream; //建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray,0,FileLength);
//建立SQL Server链接
SqlConnection Con = new SqlConnection("Data Source=Localhost;Initial Catalog=Pic;User ID=sa;Pwd=;");
String SqlCmd = "select * from pic";
DataSet ds = new DataSet();
SqlDataAdapter MyComm = new SqlDataAdapter(SqlCmd,Con);
SqlCommandBuilder mybuilder1=new SqlCommandBuilder(MyComm);
//把表存入DataSet
MyComm.Fill(ds,"pic");
DataRow p=ds.Tables["pic"].NewRow();
p["ImageData"]=FileByteArray;
p["ImageContentType"]=UpFile.ContentType;
p["ImageSize"]=UpFile.ContentLength;
ds.Tables["pic"].Rows.Add(p);
MyComm.Update(ds.Tables["pic"].Select("","",DataViewRowState.Added));
Con.Close();