在数据库的HR方案下建立一个名为TESTFILEUPLOAD的表,包含3列:主键PKID、文件名FILENAME、文件FILE(BLOB类型)。
void uploadFile()
{
FileStream objFs = new FileStream(File1.Value,FileMode.Open, FileAccess.Read);
???BinaryReader objBr = new BinaryReader(objFs);
???byte [] bytFile = objBr.ReadBytes((int)objFs.Length);
???OracleConnection objOconn = new OracleConnection("user id=system;Data Source=tsems;passWord=system");
???objOconn.Open();
???OracleCommand objOcmd = new OracleCommand();
???objOcmd.Connection = objOconn;
???objOcmd.CommandText = "INSERT INTO HR.TESTFILEUPLOAD VALUES(:VPKID,:VFILENAME , :VFILE)";
????
???objOcmd.Parameters.Add("VPKID", OracleType.VarChar);
???objOcmd.Parameters["VPKID"].Value = "2006";
???objOcmd.Parameters.Add("VFILENAME",OracleType.VarChar);
???objOcmd.Parameters["VFILENAME"].Value = Path.GetFileName(File1.Value);
???objOcmd.Parameters.Add("VFILE",OracleType.Blob,bytFile.Length);
???objOcmd.Parameters["VFILE"].Value = bytFile;
???objOcmd.ExecuteNonQuery();
???objOconn.Close();
???Response.Write("true");
}