String SqlCmd = "INSERT INTO ReportsList (report,filename,moreinfo,savedate) "+
"values (@FileByteArray,@ReportName,@MoreInfo,@SaveDate)";==〉String SqlCmd = "INSERT INTO ReportsList (report,filename,moreinfo,savedate) "+
"values (:FileByteArray,:ReportName,:MoreInfo,:SaveDate)";
"values (@FileByteArray,@ReportName,@MoreInfo,@SaveDate)";==〉String SqlCmd = "INSERT INTO ReportsList (report,filename,moreinfo,savedate) "+
"values (:FileByteArray,:ReportName,:MoreInfo,:SaveDate)";
> >> cx_Oracle, I don't know how Oracle OCI works at this low a level) -
> >> I'm passing bind variables which aren't used by the SQL statement. But
> >
> > This is definitely a limitation of Oracle. Oracle does not allow you to
> > specify variables that are not part of the statement. As far as I know
> > there is no way around this. Oracle does provide a way of returning to
> > you the bind variable names once the statement is prepared but cx_Oracle
> > does not (currently) provide that information. I have another workaround
> > for now but if you really think this would be helpful, feel free to ask
> > me for it -- this is definitely beyond the scope of the DB API but I
> > have long since stopped feeling restricted by the limitations of the API
> > (which has to accommodate each of the different database management
> > systems out there).
>
> The behaviour of cursor.execute(sql, parameters) when there are
> variables specified in `parameters` which are not needed by `sql` is
> undefined in the DB-API. However, the more I think about it, the more
> I feel that ignoring "extra" parameters is the more user-friendly
> option.
我在网上找到的同样的问题的一个人的分析,你自己看一下,对于你这个问题,许多人都遇到过,但是都没有一个很好的解决办法。
HttpPostedFile UpFile = file1.PostedFile; Int32 FileLength = 0;FileLength = UpFile.ContentLength;
//图象文件临时储存Byte数组
Byte[] FileByteArray = new Byte[FileLength];
int FileLength = file1.PostedFile.ContentLength;
byte[] FileByteArray = new byte[FileLength];
imgDataStream.Read( FileByteArray, 0, FileLength );System.Data .OracleClient .OracleParameter op1 = new OracleParameter ();
op1.OracleType = OracleType.LongRaw ;
op1.Value = FileByteArray;...
==》
CmdObj.Parameters.Add( ":FileByteArray", System.Data.OracleClient.OracleType.LongRaw, FileLength, "report" ).Value = FileByteArray;
HttpPostedFile UpFile = file1.PostedFile; //文件临时储存Byte数组
Stream imgDataStream = file1.PostedFile.InputStream;int FileLength = file1.PostedFile.ContentLength;byte[] FileByteArray = new byte[FileLength];imgDataStream.Read( FileByteArray, 0, FileLength );string message = _DO.SaveReportToDatabase (FileByteArray,this.ddlName .SelectedItem .Text ,this.calComplete .Text ,this.txtMoreInfo .Text , FileLength); this.labInfo .Text = message;
///////////////////////////////////////////////////////////////////////////////
public string SaveReportToDatabase(Byte[] FileByteArray,string ReportName,string SaveDate,string MoreInfo,int FileLength)
{
String SqlCmd = "INSERT INTO ReportsList (report,filename,moreinfo,savedate) "+
"values (:FileByteArray,:ReportName,:MoreInfo,:SaveDate)";
OracleConnection MyConn = new OracleConnection ("Data Source=ORACLE8;user=weboa;password=oa;");
OracleCommand CmdObj = new OracleCommand (SqlCmd,MyConn ); CmdObj.Parameters.Add( ":FileByteArray", System.Data.OracleClient.OracleType.LongRaw, FileLength, "report" ).Value = FileByteArray;
CmdObj.Parameters.Add( ":ReportName", System.Data.OracleClient.OracleType.VarChar , ReportName.Length , "filename" ).Value = ReportName;
CmdObj.Parameters.Add( ":MoreInfo", System.Data.OracleClient.OracleType.VarChar, MoreInfo.Length , "moreinfo" ).Value = MoreInfo;
CmdObj.Parameters.Add( ":SaveDate", System.Data.OracleClient.OracleType.DateTime ).Value = Convert.ToDateTime (SaveDate);
//打开数据库连接更新数据库
try
{
MyConn.Open ();
CmdObj.ExecuteNonQuery();
}
catch(InvalidOperationException ee)
{
return ee.Message ;
}
finally
{
MyConn.Close ();
}
return "保存成功";
}