比較郁悶的一個事情,為了修改Oracle中兩個數據庫(schema)保證數據一致,需要修改一個字段(BLOB類型)的數據,最開始寫的是
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["NEWOracleConn"].ToString());
OracleCommand cmd = new OracleCommand("UPDATE TUSER SET PHOTO=@photo WHERE userid=@id", conn);
Console.WriteLine(cmd.CommandText);
cmd.Parameters.Add("@photo",OracleType.Blob);
cmd.Parameters["@photo"].Value = photo;
cmd.Parameters.Add("@id", OracleType.Number);
cmd.Parameters["@id"].Value = id;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
在操作的時候出現錯誤,本來以為是blob字段的特殊性導致的然后繼續g.cn才發覺 原來在使用參數的時候SqlServer與Oralce的寫法不一樣
改為下面的寫法之后 一切OK
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["NEWOracleConn"].ToString());
OracleCommand cmd = new OracleCommand("UPDATE TUSER SET PHOTO=:photo WHERE userid=:id", conn);
Console.WriteLine(cmd.CommandText);
cmd.Parameters.Add("photo",OracleType.Blob);
cmd.Parameters["photo"].Value = photo;
cmd.Parameters.Add("id", OracleType.Number);
cmd.Parameters["id"].Value = id;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();