如题,代码如下
private void Button1_Click(object sender, System.EventArgs e)
{
HttpPostedFile UpFile=UPFILE.PostedFile;
FileLength=UpFile.ContentLength;
try
{
if(FileLength==0) //文件长度为零时
{
Label1.Text="<b>请你选择你要上传的文件</b>";
}
else
{
Byte[]FileByteArray=new byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UpFile.InputStream;//建立数据流对像
StreamObject.Read(FileByteArray,0,FileLength);//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
Byte[] aa=FileByteArray;
OleDbConnection con = new OleDbConnection("Provider=OraOLEDB.Oracle.1;Password=gjjywxt;Persist Security Info=True;User ID=gjjywxt;Data Source=gjjywxt");
String OledbCmd="INSERT INTO IMAGE(ImageID,ImageData) values(:ImageID,:ImageData)";
(ImageID,ImageData,ImageContentType,ImageDescription,ImageSize) values(1,'"+aa+"','"+bb+"','','"+cc+"')";
OleDbCommand CmdObj = new OleDbCommand(OledbCmd,con);
CmdObj.Parameters.Add(":ImageID",OleDbType.Numeric,17).Value =2;
CmdObj.Parameters.Add(":ImageData",OleDbType.LongVarBinary,FileLength).Value = FileByteArray;
con.Open();
CmdObj.ExecuteNonQuery();
con.Close();
Label1.Text="<p><b>OK!你已经上传成功<b><p>";
}
}
catch (Exception ex)
{
Label1.Text = ex.Message.ToString();;
}
}
}
}
imageDate为blob类型,结果老是报ora-01465错误,弄了几天没找到原因,网上也没查到合适的解决办法,我用的是oracle10.2。