2009-04-21 63 views
0

我會嘗試這種插入圖片到Oracle數據庫 - 但它不工作爲什麼在嘗試在Oracle中保存圖片時出現ORA-00936錯誤?

(在相同的代碼的SQL Server工作的優良)

string sampleImage = PicNativ; 
BinaryReader sampleBR = null; 
FileStream sampleFS = null; 
OracleConnection sampleConnection = null; 
OracleCommand sampleCommand = null; 
FileInfo sampleFI = null; 
byte[] sampleArr = null; 
try 
{ 
    if (EDIT_M == 1) 
     Oracle = "update Sex set Name = '" + txtC.Text.Trim() + 
      "',pic = @p_pic where ID like '" + txtC4.Text.Trim() + "'"; 
    else 
     Oracle = "insert into Sex (Id,Code,Name,pic) values "+ 
      "(Sex_Code.nextval,'" + txtA.Text.Trim() + "','" + 
      txtC.Text.Trim() + "', @p_pic)"; 
    sampleFI = new FileInfo(sampleImage); 
    sampleFS = new FileStream(sampleImage, FileMode.Open, FileAccess.Read); 
    sampleBR = new BinaryReader(sampleFS); 
    sampleArr = sampleBR.ReadBytes((int)sampleFI.Length); 
    using (sampleConnection = new OracleConnection(Conect)) 
    { 
     sampleConnection.Open(); 
     using (sampleCommand = new OracleCommand()) 
     { 
      sampleCommand.Connection = sampleConnection; 
      sampleCommand.CommandText = Oracle; 
      sampleCommand.Parameters. 
       Add("@p_pic", OracleDbType.Blob).Value = sampleArr; 
      sampleCommand.ExecuteNonQuery(); 
     } 
    } 
} 
finally 
{ 
    sampleBR.Close(); 
    sampleFS.Close(); 
} 
+1

「它不工作」非常含糊。你能給出確切的問題嗎?您是否收到錯誤,數據是否完全丟失,不完整或無效? – 2009-04-21 09:01:04

回答

0

如你所知,ORA-00936是缺少表達錯誤。在您的問題代碼中,您在SQL語句中使用了一個綁定變量。在Oracle中,placeholder variable starts with a colon。因此,如果你有@p_pic正確的格式是:@p_pic

在命名參數中使用&符號是Microsoft SQL Server。

相關問題