1. 程式人生 > >新增和編輯clob字段

新增和編輯clob字段

修改方法 man begin dir ans let value lB ack

#region 新的數據新增和修改方法
/// <summary>
/// 添加信息
/// </summary>
/// <returns></returns>
public static bool AddInfo(string name, string pid, string content)
{
OracleConnection conn = new OracleConnection(connectionstring);
OracleCommand cmd = conn.CreateCommand();
OracleTransaction objTran = null;
try
{
conn.Open();
objTran = conn.BeginTransaction();
cmd.Transaction = objTran;
//創建臨時clob變量
cmd.CommandText = "DECLARE dpClob CLOB; BEGIN DBMS_LOB.CREATETEMPORARY(dpClob, False, 0); :tmpClob := dpClob; END;";
OracleParameter op1 = new OracleParameter("tmpClob", OracleType.Clob);
op1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(op1);
cmd.ExecuteNonQuery();
OracleLob tempLob;
tempLob = (OracleLob)cmd.Parameters[0].Value;
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
byte[] buffer = Encoding.Unicode.GetBytes(content);
tempLob.Write(buffer, 0, buffer.Length);//將值寫入臨時變量中
tempLob.EndBatch();
cmd.Parameters.Clear();
cmd.CommandText = "insert into t_yingjiinfo (id,nodename,pid,content) values ( seq_t_yingjiinfo.nextval,‘" + name + "‘, " + pid + ",:contentText)";
cmd.CommandType = CommandType.Text;
OracleParameter op2 = new OracleParameter("contentText", OracleType.Clob);
op2.Value = tempLob;
cmd.Parameters.Add(op2);
cmd.ExecuteNonQuery();
objTran.Commit();
cmd.Parameters.Clear();
return true;

}
catch
{
objTran.Rollback();
return false;
}

finally
{
objTran.Dispose();
cmd.Dispose();
conn.Close();
conn.Dispose();

}


}


/// <summary>
/// 更新數據 更新一般修理二維碼字段 暫時只有陜西省
/// </summary>
/// <returns></returns>
public static bool UpdateInfo(string bianhao, string content)
{
OracleConnection conn = new OracleConnection(connectionstring);
OracleCommand cmd = conn.CreateCommand();
OracleTransaction objTran = null;
try
{
conn.Open();
objTran = conn.BeginTransaction();
cmd.Transaction = objTran;
cmd.CommandText = "DECLARE dpClob CLOB; BEGIN DBMS_LOB.CREATETEMPORARY(dpClob, False, 0); :tmpClob := dpClob; END;";
OracleParameter op1 = new OracleParameter("tmpClob", OracleType.Clob);
op1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(op1);
cmd.ExecuteNonQuery();
OracleLob tempLob;
tempLob = (OracleLob)cmd.Parameters[0].Value;
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
byte[] buffer = Encoding.Unicode.GetBytes(content);
tempLob.Write(buffer, 0, buffer.Length);
tempLob.EndBatch();
cmd.Parameters.Clear();
cmd.CommandText = "update wh_qrcode set qrcode = :contentText where bianhao = ‘" + bianhao + "‘";
cmd.CommandType = CommandType.Text;
OracleParameter op2 = new OracleParameter("contentText", OracleType.Clob);
op2.Value = tempLob;
cmd.Parameters.Add(op2);
cmd.ExecuteNonQuery();
objTran.Commit();
cmd.Parameters.Clear();
return true;
}

catch
{
objTran.Rollback();
return false;
}

finally
{
objTran.Dispose();
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
#endregion

新增和編輯clob字段