2016-11-15 78 views
0

我想用C#中的ado.net更新CLOB數據類型,但我不知道如何匹配字符串數據類型(在C#中)與CLOB數據類型(在oracle中) :在Oracle不一致的數據類型預期的CLOB,但得到字符

public static DBOperation updateMasterChild(MasterChild v_child = null, List<MasterChild> childRen = null) 
    { 
     if (v_child == null && childRen == null) 
      throw new ValidationFailedException("Must contain one MasterChild object for updating at least."); 
     if (childRen == null) 
     { 
      childRen = new List<MasterChild>(); 
     } 

     if (v_child != null) 
      childRen.Add(v_child); 

     OracleDataAdapter da = new OracleDataAdapter(); 
     StringBuilder sb = new StringBuilder(); 
     sb = sb.Append(" update MSWSCEMASTERCHILD set ticket_id = case when :ticket_id_1 is null then ticket_id else :ticket_id end,"); 
     sb = sb.Append(" LONGREFERENCEDATA = case when :LONGREFERENCEDATA_1 is null then LONGREFERENCEDATA else :LONGREFERENCEDATA end "); 
     sb = sb.Append(" where id = :id and step_count = :step_count "); 

     using (OracleConnection oraC = new OracleConnection(conStr)) 
     { 
      OracleCommand cmd = new OracleCommand(); 
      cmd.Connection = oraC; 
      cmd.CommandText = sb.ToString(); 

      oraC.Open(); 
      cmd.Transaction = oraC.BeginTransaction(); 

      try 
      { 
       foreach (MasterChild child in childRen) 
       { 
        cmd.Parameters.Clear(); 

        cmd.Parameters.AddWithValue(":ticket_id_1", child.TicketId); 
        cmd.Parameters.AddWithValue(":ticket_id", child.TicketId); 

        cmd.Parameters.AddWithValue(":LONGREFERENCEDATA_1", child.LONGREFERENCEDATA); 
        cmd.Parameters.AddWithValue(":LONGREFERENCEDATA", child.LONGREFERENCEDATA); 

        cmd.Parameters.AddWithValue(":id", child.Id); 
        cmd.Parameters.AddWithValue(":step_count", child.StepCount); 

        cmd.ExecuteNonQuery(); 
       } 
       cmd.Transaction.Commit(); 
      } 
      catch (Exception ex) 
      { 
       cmd.Transaction.Rollback(); 
       throw ex; 
      } 
     } 
     return DBOperation.Success; 
    } 

LONGREFERENCEDATA是CLOB類型和屬性LONGREFERENCEDATA在子對象是字符串,如果我刪除此更新此字段,這是確定的,但如果我寫的更新包括CLOB字段,它失敗,並得到一個異常:預期的CLOB,但得到了字符。

我不知道爲什麼以及如何解決這個問題。請你幫忙提供一些建議或解決方案?

回答

0

使用CLOB Oracle數據不像使用基本數據類型那麼簡單。有關在ADO.NET中讀取\寫入Oracle CLOB數據的示例,請參見link

相關問題